-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
List comprehensions sometimes call iter(iter(v))
instead of just iter(v)
#128211
Labels
type-bug
An unexpected behavior, bug, or error
Comments
DemiMarie
added a commit
to DemiMarie/qubes-desktop-linux-manager
that referenced
this issue
Dec 24, 2024
Python 3.13 list comprehensions are buggy [1]: [i for i in x] calls iter(iter(x)) instead of just iter(x). Work around the bug by having UpdateListIter have a __iter__(self) that just returns self. This is the same thing that the standard library does: x = iter([]) print(x is iter(x)) prints True. [1]: python/cpython#128211
Duplicate of #128161 |
The idea that iterators should be iterable is not recent, but was part of the design introduced, I believe, in 2.2. |
DemiMarie
added a commit
to DemiMarie/qubes-desktop-linux-manager
that referenced
this issue
Dec 31, 2024
Python iterators are required to implement an __iter__() that returns self [1]. CPython doesn't check this consistently, but the requirement is still there, so the existing code is buggy. Python 3.13 started checking this in list comprehensions, resulting in exceptions being thrown. Fix the bug by having __iter__() return self, as required by the iterator protocol. This worked on Python 3.13 and below, but broke in 3.13.1 [2]. [1]: https://docs.python.org/3/glossary.html#term-iterator [2]: python/cpython#128211
DemiMarie
added a commit
to DemiMarie/qubes-desktop-linux-manager
that referenced
this issue
Jan 4, 2025
Python iterators are required to implement an __iter__() that returns self [1]. CPython doesn't check this consistently, but the requirement is still there, so the existing code is buggy. Python 3.13 started checking this in list comprehensions, resulting in exceptions being thrown. Fix the bug by having __iter__() return self, as required by the iterator protocol. This worked on Python 3.13 and below, but broke in 3.13.1 [2]. [1]: https://docs.python.org/3/glossary.html#term-iterator [2]: python/cpython#128211
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
Bug description:
A development version of the Qubes OS updater gave the following traceback:
However, this makes no sense. The code can be found at https://github.com/QubesOS/qubes-desktop-linux-manager/blob/a3e4d177785bbc1b1ee72bd7cd83ef7b8a4e8827/qui/updater/utils.py#L300-L309, where
self
is anListWrapper
instance. Its__iter__
method returns anUpdateListIter
, which is a valid iterator. However,UpdateListIter
does not have its own__iter__
method. Adding a method that returnsself
makes the problem go away.A small reproducer is below:
On Python 3.12, this works (and prints
[]
). On Python 3.13, this raisesTypeError
.At least some standard library iterators (such as
iter([])
have an__iter__(self)
that returnsself
, as shown by the following program printingTrue
on both 3.13 and 3.14:CPython versions tested on:
3.13
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: