Skip to content

GH-141312: Allow only integers to longrangeiter_setstate state#141317

Merged
serhiy-storchaka merged 18 commits into
python:mainfrom
sergey-miryanov:141312-longrange-setstate-float
Nov 14, 2025
Merged

GH-141312: Allow only integers to longrangeiter_setstate state#141317
serhiy-storchaka merged 18 commits into
python:mainfrom
sergey-miryanov:141312-longrange-setstate-float

Conversation

@sergey-miryanov

@sergey-miryanov sergey-miryanov commented Nov 9, 2025

Copy link
Copy Markdown
Contributor

Only integers should be allowed for the start value in longrangeiter.

Two extra checks were added:

  1. The first one checks that setting a float value for __setstate__ for rangeiter fails
  2. The second check does the same for longrangeiter.

I made the error message for longrangeiter similar to that for rangeiter.

@sergey-miryanov

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka Could you please take a look?
I'm not sure should we add a news entry here.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not simply check state? Normally, it can only be int.

Using PyLong_Check() is not enough -- it would pass for an int subclass with overridden __radd__, __mul__, etc. PyLong_CheckExact() is needed.

@sergey-miryanov

Copy link
Copy Markdown
Contributor Author

Should we change PyLong_Check to PyLong_CheckExact in compute_range_length then?

Comment thread Objects/rangeobject.c
@picnixz

picnixz commented Nov 9, 2025

Copy link
Copy Markdown
Member

I'm not sure should we add a news entry here.

Yes we should. It's a bug fix. The rule is that most bugfixes have NEWS.

Comment thread Lib/test/test_range.py Outdated
Comment thread Objects/rangeobject.c Outdated
@sergey-miryanov

Copy link
Copy Markdown
Contributor Author

It is ready for review.
@serhiy-storchaka @picnixz Could you please take a look?

Comment thread Objects/rangeobject.c Outdated
@sergey-miryanov

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka Could you please take a look?

Comment thread Misc/NEWS.d/next/Core_and_Builtins/2025-11-10-23-07-06.gh-issue-141312.H-58GB.rst Outdated
Comment thread Lib/test/test_range.py Outdated
sergey-miryanov and others added 2 commits November 14, 2025 10:47
…e-141312.H-58GB.rst

Co-authored-by: Mikhail Efimov <efimov.mikhail@gmail.com>

@efimov-mikhail efimov-mikhail left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sergey-miryanov

Copy link
Copy Markdown
Contributor Author

Done!

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yet few nitpicks.

Comment thread Lib/test/test_range.py Outdated
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2025-11-10-23-07-06.gh-issue-141312.H-58GB.rst Outdated
@sergey-miryanov

Copy link
Copy Markdown
Contributor Author

Done, please take a look.

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. 👍

@serhiy-storchaka serhiy-storchaka enabled auto-merge (squash) November 14, 2025 12:16
@efimov-mikhail

efimov-mikhail commented Nov 14, 2025

Copy link
Copy Markdown
Member

I suggest to backport this PR for 3.13 and 3.14 since there's an assert crash in debug builds on these Python versions.

@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Nov 14, 2025
@serhiy-storchaka serhiy-storchaka merged commit 10bec7c into python:main Nov 14, 2025
50 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @sergey-miryanov for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 14, 2025
…ythonGH-141317)

This fixes an assertion error when the new computed start is not an integer.
(cherry picked from commit 10bec7c)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
@miss-islington-app

Copy link
Copy Markdown

Sorry, @sergey-miryanov and @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 10bec7c1eb3ee27f490a067426eef452b15f78f9 3.13

@bedevere-app

bedevere-app Bot commented Nov 14, 2025

Copy link
Copy Markdown

GH-141559 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 14, 2025
@sergey-miryanov

Copy link
Copy Markdown
Contributor Author

Looking to manually backport it to 3.13.

@bedevere-app

bedevere-app Bot commented Nov 14, 2025

Copy link
Copy Markdown

GH-141568 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Nov 14, 2025
sergey-miryanov added a commit to sergey-miryanov/cpython that referenced this pull request Nov 14, 2025
… state (pythonGH-141317)

This fixes an assertion error when the new computed start is not an integer.
(cherry picked from commit 10bec7c)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request Nov 15, 2025
…GH-141317) (GH-141568)

This fixes an assertion error when the new computed start is not an integer.
(cherry picked from commit 10bec7c)
@sergey-miryanov

Copy link
Copy Markdown
Contributor Author

Thanks everyone for review!

serhiy-storchaka pushed a commit that referenced this pull request Nov 15, 2025
…GH-141317) (GH-141559)

This fixes an assertion error when the new computed start is not an integer.
(cherry picked from commit 10bec7c)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
…ythonGH-141317)

This fixes an assertion error when the new computed start is not an integer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants