➜

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.

作者 remi.lapeyre
收信人 Eric Appelt, cheryl.sabella, docs@python, mark.dickinson, ncoghlan, remi.lapeyre, serhiy.storchaka, xtreak
日期 2019-05-06.14:11:12
SpamBayes Score -1.0
Marked as misclassified 是
Message-id <1557151873.07.0.266148452873.issue33039@roundup.psfhosted.org>
In-reply-to
内容
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__.
历史
日期 用户 动作 参数
2019-05-06 14:11:13remi.lapeyre修改recipients: + remi.lapeyre, mark.dickinson, ncoghlan, docs@python, serhiy.storchaka, Eric Appelt, cheryl.sabella, xtreak
2019-05-06 14:11:13remi.lapeyre修改messageid: <1557151873.07.0.266148452873.issue33039@roundup.psfhosted.org>
2019-05-06 14:11:13remi.lapeyre链接issue33039 messages
2019-05-06 14:11:12remi.lapeyre创建