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 mark.dickinson
Recipients mark.dickinson
Date 2021-08-22.09:17:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1629623877.06.0.26111591106.issue44977@roundup.psfhosted.org>
In-reply-to
Content
The int constructor, when applied to a general Python object `obj`, first looks for an __int__ method, then for an __index__ method, and then finally for a __trunc__ method.

The delegation to __trunc__ used to be useful: it meant that users could write a custom class SomeNumber with the property that:

- SomeNumber instances supported 'int' calls, returning a truncated value, but
- SomeNumber instances weren't usable in indexing, chr() calls, and all the various other calls that implicitly invoked __int__.

class SomeNumber:
    def __trunc__(self):
       <return truncated value for self>

However, with Python >= 3.10, we no longer use __int__ implicitly for argument conversion in internal code. So the second point above is no longer a concern, and SomeNumber can now simply be written as

class SomeNumber:
    def __int__(self):
       <return truncated value for self>

This decouples int from __trunc__ and leaves __trunc__ as simply the support for the math.trunc function.
History
Date User Action Args
2021-08-22 09:17:57mark.dickinsonsetrecipients: + mark.dickinson
2021-08-22 09:17:57mark.dickinsonsetmessageid: <1629623877.06.0.26111591106.issue44977@roundup.psfhosted.org>
2021-08-22 09:17:57mark.dickinsonlinkissue44977 messages
2021-08-22 09:17:56mark.dickinsoncreate