Nick Coghlan added the comment:

OK, something appears to have gotten confused along the way here. Barry's 
original problem report was that operator.index() was returning a different 
answer than operator.__index__() for int subclasses. Absolutely nothing to do 
with the int builtin at all. While the fact int() *may* return int subclasses 
isn't especially good, it's also a longstanding behaviour.

The problem Barry reports, where a subclassing based proxy type isn't reverting 
to a normal integer when accessed via operator.index() despite defining 
__index__() to do exactly that should be possible to fix just by applying the 
stricter check specifically in PyNumber_Index.

Expanding the scope to cover __int__() and __trunc__() as well would be much, 
much hairier, as those are much older interfaces, and used in a wider variety 
of situations. We specifically invented __index__() to stay away from that mess 
while making it possible to explicitly indicate that a type supports a lossless 
conversion to int rather than a potentially lossy one.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17576>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to