-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
GH-141312: Allow only integers to longrangeiter_setstate state #141317
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
base: main
Are you sure you want to change the base?
GH-141312: Allow only integers to longrangeiter_setstate state #141317
Conversation
|
@serhiy-storchaka Could you please take a look? |
serhiy-storchaka
left a comment
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.
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.
|
Should we change |
Yes we should. It's a bug fix. The rule is that most bugfixes have NEWS. |
|
It is ready for review. |
|
@serhiy-storchaka Could you please take a look? |
| @@ -0,0 +1,2 @@ | |||
| Restict passing of non-integer object to the ``longrangeiter.__setstate__``. | |||
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.
| Restict passing of non-integer object to the ``longrangeiter.__setstate__``. | |
| Restrict passing of non-integer object to the ``longrangeiter.__setstate__``. |
|
|
||
| class I: | ||
| def __int__(self): return 2 | ||
| def __index__(self): return 2 |
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.
Why we define both __int__ and __index__ methods?
Only integers should be allowed for the start value in
longrangeiter.Two extra checks were added:
__setstate__forrangeiterfailslongrangeiter.I made the error message for
longrangeitersimilar to that forrangeiter.compute_range_length: Assertion PyLong_Check(start)' failed#141312