Skip to content

gh-132629: Deprecate acception out of range values for unsigned integers in PyArg_Parse #132630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Apr 17, 2025

For unsigned integer formats in the PyArg_Parse* funcions, accepting Python integers with value that is larger than the maximal value the corresponding C type or less than the minimal value for the corresponding signed integer type is now deprecated.


📚 Documentation preview 📚: https://cpython-previews--132630.org.readthedocs.build/

… integers in PyArg_Parse

For unsigned integer formats in the PyArg_Parse* funcions,
accepting Python integers with value that is larger than
the maximal value the corresponding C type or less than
the minimal value for the corresponding signed integer type
is now deprecated.
#ifndef Py_GIL_DISABLED
# define Py_LIMITED_API 0x030d0000
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may be able to continue using the limited C API, since PyLong_AsNativeBytes() was added to the limited C API: #132640

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to wait for Python 3.15 to introduce this new DeprecationWarning? I would prefer to avoid adding new warnings later in the 3.14 dev cycle.

I like the overall change :-)

@serhiy-storchaka
Copy link
Member Author

This is not a blocker. But the sooner we add warnings, the sooner we can turn them into errors.

Recently, you and me added many uses of unsigned integer converters in the socket addresses parsing code. This fixed errors, and allowed to pass values that exceed the limit of corresponding signed integer type, but made the new code more error prone, because passing value that exceeds the limit of an unsigned integer type does not lead to exception. This is the main reason I created that PR now. The idea I proposed a year ago: capi-workgroup/api-evolution#49.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants