Message341505
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__. |
|
Date |
User |
Action |
Args |
2019-05-06 14:11:13 | remi.lapeyre | set | recipients:
+ remi.lapeyre, mark.dickinson, ncoghlan, docs@python, serhiy.storchaka, Eric Appelt, cheryl.sabella, xtreak |
2019-05-06 14:11:13 | remi.lapeyre | set | messageid: <1557151873.07.0.266148452873.issue33039@roundup.psfhosted.org> |
2019-05-06 14:11:13 | remi.lapeyre | link | issue33039 messages |
2019-05-06 14:11:12 | remi.lapeyre | create | |
|