This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients Arfrever, alex, barry, docs@python, eric.snow, ethan.furman, mark.dickinson, ncoghlan, python-dev, serhiy.storchaka, vstinner
Date 2013-12-11.20:02:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1386792132.28.0.121459857512.issue17576@psf.upfronthosting.co.za>
In-reply-to
Content
I first committed safe part of patch, which doesn't change behavior, only adds warnings and tests. Here is other part (very simple), which change behavior (in sum they are equal to issue17576_v3.patch with minor changes).

* PyNumber_Index() now calls __index__() for int subclasses.

>>> class A(int):
...     def __index__(self): return 1
... 
>>> import operator
>>> operator.index(A())

Returns 0 without patch and 1 with patch.

* PyNumber_Long() now calls __int__() on result of __trunc__() if it is int subclass instance.

>>> class A:
...     def __trunc__(self): return True
... 
>>> int(A())

Returns True without patch and 1 with patch.

* PyLong_As*() functions (but not all) call __int__() for int subclasses (I'm not sure this is right).

>>> class A(int):
...     def __int__(self): return 42
... 
>>> chr(A(43))

Returns '+' without patch and '*' with patch.
History
Date User Action Args
2013-12-11 20:02:12serhiy.storchakasetrecipients: + serhiy.storchaka, barry, mark.dickinson, ncoghlan, vstinner, Arfrever, alex, docs@python, ethan.furman, python-dev, eric.snow
2013-12-11 20:02:12serhiy.storchakasetmessageid: <1386792132.28.0.121459857512.issue17576@psf.upfronthosting.co.za>
2013-12-11 20:02:12serhiy.storchakalinkissue17576 messages
2013-12-11 20:02:12serhiy.storchakacreate