-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Regression of 3.13.1 with iterator creation being duplicated #127682
Comments
This is an expected result from the change @brianschubert linked, which fixes a crash. Our belief was that |
It does return
But nobody ever promised to not have a side effect in there, and calling it twice is strange, which one of the two gets used for what there? Right now I cannot distinguish the two. As for real-life code relevance, I am more than willing to admit this is garbage code. I just did a bunch of prints in iterator functions to see when they get called, and now they're getting called more often. Would it have to be a performance regression to make two calls? |
Actually, there is a PR for main branch related to this issue: But on 3.13 current behavior is not a bug. |
The problem is specific to generator expressions which have acted in a subtly different way from generators that (almost) no one noticed. For a generator, any iteration occurs once the generator is executed. For generator expressions creating an iterator from the iterable happened when the generator expression is created. However there was no check that the iteration variable held an iterator when the generator expression executed, which could lead to a crash in exceptional circumstances. This can be seen by disassembling this function: def f(seq):
return (x for x in seq) Up to 3.13
Now:
What I would like:
I think we should make generator expressions behave exactly like generators. It seems surprising that they would not. |
FWIW we have discovered a segfault in libdnf because of this. The problem pre-existed in libdnf but was never triggered because nobody ever did https://bugzilla.redhat.com/2330562 rpm-software-management/libdnf#1682 |
And another one: https://bugzilla.redhat.com/2331665 rpm-software-management/libcomps#116 I realize both of those use cases did it wrong, but this Python's new behavior tends to uncover problems that would otherwise never bite anybody. |
Bug report
Bug description:
For my Python compiler Nuitka, I use CPython as the oracle of what the correct behaviour is. I am running some tests that I used to clarify the behavior from decades ago, in this case I wanted to know when exactly the iterator creation is used. I striped this test a bunch, so the regression is still visible. I first noticed the issue on GitHub Actions, where 3.13.0 got replaced with 3.13.1 for Windows and Linux, but it applies to all OSes. See below for a diff, that the same iterator is created multiple times.
The unified diff between 3.13.0 output (and basically all Python versions before) and 3.13.1 output.
The duplicated prints out the iterator creation are new. This is not optimal and new. I don't know if the iterator being through a slot cause cause this or what it is. I checked if
generator.c
changed but I think it didn't at all.My self compiled Python 3.13.1 for Linux and the official Windows download agree in behaviour.
CPython versions tested on:
3.13
Operating systems tested on:
Linux, Windows
The text was updated successfully, but these errors were encountered: