Skip to content

list iterator __setstate__() differs for exhausted iterator GIL vs. non-GIL #129139

Description

@tom-pytel

Or is this too pedantic?

GIL enabled:

$ ./python
Python 3.14.0a4+ (heads/main:f3980af38b, Jan 21 2025, 11:34:12) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> it = iter([1]); list(it)
[1]
>>> it.__setstate__(0); list(it)
[]

GIL disabled:

$ ./python
Python 3.14.0a4+ experimental free-threading build (heads/main:f3980af38b, Jan 21 2025, 11:31:38) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> it = iter([1]); list(it)
[1]
>>> it.__setstate__(0); list(it)
[1]

v3.14, current main, its a one line fix.

Linked PRs

Activity

  1. eendebakpt commented on Jan 21, 2025

    @eendebakpt
    Contributor

    @Yhg1s Your changes in #128637 might result in a similar behavior change for tuple iterators as is described here for list iterators.

  2. Yhg1s commented on Jan 22, 2025

    @Yhg1s
    Member

    Yes, indeed. It's not difficult to fix, by the way, it just requires an extra check in the relevant __setstate__ methods. I'm not sure it's worth it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions