[New-bugs-announce] [issue20092] type() constructor should bind __int__ to __index__ when __index__ is defined and __int__ is not

Ethan Furman report at bugs.python.org
Sat Dec 28 20:56:32 CET 2013


New submission from Ethan Furman:

In order to create a coherent integer type class both __int__ and __index__ must be defined or the resulting instances will behave inconsistently in different places.

For example, if __index__ is not defined then the class cannot be used in slices, and if __int__ is not defined then int(integer_type) will fail.

At this point the programmer must remember to define both, but since they should return the same value we can have the type constructor automatically assign __int__ to __index__ when the latter is defined and the former is not.  This would be similar to how we currently treat __ne__ when __eq__ is defined.

----------
messages: 207048
nosy: ethan.furman
priority: low
severity: normal
status: open
title: type() constructor should bind __int__ to __index__ when __index__ is defined and __int__ is not
type: enhancement
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20092>
_______________________________________


More information about the New-bugs-announce mailing list