Skip to content

Conversation

@sergey-miryanov
Copy link
Contributor

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

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
Contributor Author

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

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a 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.

@sergey-miryanov
Copy link
Contributor Author

Should we change PyLong_Check to PyLong_CheckExact in compute_range_length then?

@picnixz
Copy link
Member

picnixz commented Nov 9, 2025

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.

@sergey-miryanov
Copy link
Contributor Author

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

@sergey-miryanov
Copy link
Contributor Author

@serhiy-storchaka Could you please take a look?

@@ -0,0 +1,2 @@
Restict passing of non-integer object to the ``longrangeiter.__setstate__``.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Member

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?

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.

4 participants