Skip to content

Docs for PyLong_AsInt32/64() don't mention support for __index__() method #137368

@skirpichev

Description

@skirpichev

c.f. PyLong_AsUInt32/64():

If obj is not an instance of PyLongObject, first call its __index__() method (if present) to convert it to a PyLongObject.

In fact, there is no difference for signed/unsigned:

def test_long_asint32(self):
# Test PyLong_AsInt32() and PyLong_FromInt32()
to_int32 = _testlimitedcapi.pylong_asint32
from _testcapi import INT32_MIN, INT32_MAX
self.check_long_asint(to_int32, INT32_MIN, INT32_MAX)

def test_long_asuint32(self):
# Test PyLong_AsUInt32() and PyLong_FromUInt32()
as_uint32 = _testlimitedcapi.pylong_asuint32
from _testcapi import UINT32_MAX
self.check_long_asint(as_uint32, 0, UINT32_MAX,
negative_value_error=ValueError)

where check_long_asint() tests __index__() dunder per default:
def check_long_asint(self, func, min_val, max_val, *,
use_index=True,
mask=False,
negative_value_error=OverflowError):

So, same note should be added for PyLong_AsInt32/64()

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixesdocsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy