A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2019-February/156380.html below:

[Python-Dev] int() and math.trunc don't accept objects that only define __index__

[Python-Dev] int() and math.trunc don't accept objects that only define __index__ [Python-Dev] int() and math.trunc don't accept objects that only define __index__Rémi Lapeyre remi.lapeyre at henki.fr
Tue Feb 19 08:55:38 EST 2019
Another point in favor of the change I just noticed is that int()
accept objects defining __index__ as its `base` argument:


    Python 3.7.2 (default, Jan 13 2019, 12:50:01)
    [Clang 10.0.0 (clang-1000.11.45.5)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> class MyInt:
    ...     def __index__(self):
    ...             return 4
    ...
    >>> int("3", base=MyInt())
    3
    >>> int(MyInt())
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: int() argument must be a string, a bytes-like object or
a number, not 'MyInt'
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4