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, mjacob, ncoghlan, python-dev, rhettinger, serhiy.storchaka, vstinner
Date 2020-05-28.08:10:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1590653459.72.0.928385391851.issue17576@roundup.psfhosted.org>
In-reply-to
Content
The current status:

* Decimal and Fraction are no longer automatically converted to int when pass to functions implemented in C. PyLong_AsLong() etc no longer call __int__. (see issue36048 and issue37999)
* operator.index() and PyNumber_Index() always return an instance of exact type int. (see issue40792)
* int() and PyNumber_Long() always return an instance of exact type int. (see issue26984)
* __index__ is used as a fallback if __int__ is not defined. (see issue20092)

But:

* __index__ and __int__ are not called for int subclasses in operator.index() and int() (also in the C API PyNumber_Index(), PyNumber_Long(), PyLong_AsLong(), etc).
* Instances of int sublasses are accepted as result of __index__ and __int__ (but it is deprecated).
* The Python implementation of operator.index() differs from the C implementation in many ways. (see issue18712)

What I prefer as solutions of the remaining issues:

* It is good to not call __index__ and __int__ for int subclasses. __index__ and __int__ were   designed for converting non-integers to int. There are no good use cases for overriding __index__ and __int__ in int subclasses, and calling them is just a waste of time. We should just document this behavior.

* Undeprecate accepting __index__ and __int__ returning instances of int sublasses. There is no difference from the side of using int and index(), but it can simplify user implementations of __index__ and __int__.

* Either sync the pure Python implementation of operator.index() with the C implementation or get rid of Python implementation of the operator module at all.
History
Date User Action Args
2020-05-28 08:10:59serhiy.storchakasetrecipients: + serhiy.storchaka, barry, rhettinger, ncoghlan, vstinner, Arfrever, alex, docs@python, ethan.furman, python-dev, eric.snow, mjacob
2020-05-28 08:10:59serhiy.storchakasetmessageid: <1590653459.72.0.928385391851.issue17576@roundup.psfhosted.org>
2020-05-28 08:10:59serhiy.storchakalinkissue17576 messages
2020-05-28 08:10:59serhiy.storchakacreate