Author remi.lapeyre
Recipients Eric Appelt, cheryl.sabella, docs@python, mark.dickinson, ncoghlan, remi.lapeyre, serhiy.storchaka, xtreak
Date 2019-05-06.14:11:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1557151873.07.0.266148452873.issue33039@roundup.psfhosted.org>
In-reply-to
Content
Hi Cheryl,

thanks for the ping.

I wasn't sure my patch was correct but reading typeobject.c:add_operators(), it is actually more straight-forward than I thought.


Serhiy Storchaka: This is indeed a duplicate of issue20092. I believe the solution proposed by Nick Coghlan is better than the one of Amitava Bhattacharyya, "adding a call to `nb_index` (if that slot exists) in `_PyLong_FromNbInt`" though.


One thing to note regarding the proposed patch: the following stops to work and raises a RecursionError since __index__ == __int__:

        class MyInt(int):
            def __index__(self):
                return int(self) + 1

I changed test_int_subclass_with_index() as `int(self) + 1` is the same thing as `self + 1` for int subclasses. I don't think this sort of code should appear in the wild but if you think it is important not to break compatibility here, I think I could check for number subclasses before overriding __index__.
History
Date User Action Args
2019-05-06 14:11:13remi.lapeyresetrecipients: + remi.lapeyre, mark.dickinson, ncoghlan, docs@python, serhiy.storchaka, Eric Appelt, cheryl.sabella, xtreak
2019-05-06 14:11:13remi.lapeyresetmessageid: <1557151873.07.0.266148452873.issue33039@roundup.psfhosted.org>
2019-05-06 14:11:13remi.lapeyrelinkissue33039 messages
2019-05-06 14:11:12remi.lapeyrecreate