GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-132629: Deprecate acception out of range values for unsigned integers in PyArg_Parse by serhiy-storchaka · Pull Request #132630 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Apr 17, 2025 •
edited by github-actions Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

  • Issue: Deprecate accepting out of range values for unsigned integers in PyArg_Parse #132629

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
pythongh-132629: Deprecate acception out of range values for unsigned…
fbc7873
… 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.
@serhiy-storchaka
serhiy-storchaka requested review from encukou and vstinner April 17, 2025 09:50
@serhiy-storchaka
serhiy-storchaka requested review from a team and erlend-aasland as code owners April 17, 2025 09:50
@bedevere-app bedevere-app Bot added the awaiting core review label Apr 17, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Apr 17, 2025
Deprecate accepting out of range values for unsigned integers in PyArg_Parse #132629
Closed
@serhiy-storchaka serhiy-storchaka mentioned this pull request Apr 17, 2025
Conversion to unsigned integers capi-workgroup/api-evolution#49
Open
@serhiy-storchaka
Fix compilation.
ddd9ee5
vstinner
vstinner reviewed Apr 23, 2025
View reviewed changes
Comment thread Modules/fcntlmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner reviewed Apr 23, 2025
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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 :-)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka

serhiy-storchaka commented Apr 23, 2025

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka added 4 commits April 23, 2025 18:59
@serhiy-storchaka
Merge branch 'main' into PyArg_Parse-unsigned-ints
ffa69cd
@serhiy-storchaka
Use the limited C API again.
478d396
@serhiy-storchaka
Merge branch 'main' into PyArg_Parse-unsigned-ints
dc1b80b
@serhiy-storchaka
Fix merge error.
be4f26b
vstinner
vstinner reviewed May 9, 2025
View reviewed changes
Comment thread Doc/whatsnew/3.14.rst Outdated
the maximal value the corresponding C type or less than
the minimal value for the corresponding signed integer type
is now deprecated.
(Contributed by Serhiy Storchaka in :gh:`132629`.)

@vstinner vstinner May 9, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You should move this entry to Doc/whatsnew/3.15.rst.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Tools/clinic/libclinic/converters.py Outdated
{{{{
unsigned long ival = PyLong_AsUnsignedLongMask({argname});
if (ival == (unsigned long)-1 && PyErr_Occurred()) {{{{
Py_ssize_t _bytes = PyLong_AsNativeBytes({argname}, &{paramname}, sizeof(unsigned char),

@vstinner vstinner May 9, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Can you factorize this code? It's copied 4 times. For example, write a function which returns this template, with an argument: the sizeof() argument.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@serhiy-storchaka serhiy-storchaka May 13, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Actually, it is not the exactly the same. For unsigned long and unsigned long long it does additional check (historically).

But well, it can be factorized, and with recent changes in Argument Clinic, even more code can be factorized.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
serhiy-storchaka added 3 commits May 13, 2025 17:32
@serhiy-storchaka
Merge branch 'main' into PyArg_Parse-unsigned-ints
e5aecdc
@serhiy-storchaka
Move the What's New entry.
bb2ef60
@serhiy-storchaka
Factorize the Argument Clinic code.
23b4c08
vstinner
vstinner reviewed May 16, 2025
View reviewed changes
Comment thread Doc/c-api/arg.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/c-api/arg.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/C_API/2025-04-17-12-37-27.gh-issue-132629.01ArwX.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/fcntlmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner approved these changes May 16, 2025
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM, event if I would prefer to also emit deprecation warnings for (any) negative value for unsigned types.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels May 16, 2025
serhiy-storchaka and others added 6 commits May 23, 2025 20:12
@serhiy-storchaka @vstinner
Apply suggestions from code review
d3c4765
Co-authored-by: Victor Stinner <[email protected]>
@serhiy-storchaka
Merge branch 'main' into PyArg_Parse-unsigned-ints
960e817
@serhiy-storchaka
Update documentation.
f51a052
@serhiy-storchaka
Merge branch 'main' into PyArg_Parse-unsigned-ints
bb94544
@serhiy-storchaka
Merge branch 'main' into PyArg_Parse-unsigned-ints
f45dca9
@serhiy-storchaka @vstinner
Update Modules/fcntlmodule.c
5ee1480
Co-authored-by: Victor Stinner <[email protected]>
@serhiy-storchaka
serhiy-storchaka merged commit e18829a into python:main Jul 13, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Jul 13, 2025
@serhiy-storchaka
serhiy-storchaka deleted the PyArg_Parse-unsigned-ints branch July 13, 2025 09:44
picnixz pushed a commit to picnixz/cpython that referenced this pull request Jul 13, 2025
@serhiy-storchaka @picnixz
pythongh-132629: Deprecate accepting out-of-range values for unsigned…
1503249
… integers in PyArg_Parse (pythonGH-132630)

For unsigned integer formats in the PyArg_Parse* functions,
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.
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
@serhiy-storchaka @taegyunkim
pythongh-132629: Deprecate accepting out-of-range values for unsigned…
a0ef472
… integers in PyArg_Parse (pythonGH-132630)

For unsigned integer formats in the PyArg_Parse* functions,
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.
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
@serhiy-storchaka @Agent-Hellboy
pythongh-132629: Deprecate accepting out-of-range values for unsigned…
78576be
… integers in PyArg_Parse (pythonGH-132630)

For unsigned integer formats in the PyArg_Parse* functions,
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes
@encukou encukou Awaiting requested review from encukou
@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@serhiy-storchaka @vstinner
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.