Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-125038: redundant GET_ITER instructions are removed from genexpr code#126408
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
gh-125038: redundant GET_ITER instructions are removed from genexpr code#126408
Uh oh!
There was an error while loading.Please reload this page.
Conversation
efimov-mikhail commentedNov 4, 2024
ZeroIntensity commentedNov 6, 2024
I'll do the initial review on this later today. In the meantime, you can rebase against main to fix the JIT failures (seegh-126465). |
…nexpr codeAdds CHECK_ITERABLE instruction. It checks that TOS is iterable orasync iterable. Redundant GET_ITER and GET_AITER instructions areremoved from generator expression code.
9bbdf16 toaffb1f8CompareZeroIntensity commentedNov 6, 2024
For future reference, don't force push. Everything is squashed onto main anyway. |
efimov-mikhail commentedNov 6, 2024
I've used the Github button "rebase", it made force push. |
JelleZijlstra commentedNov 6, 2024
I like to use the "Update branch" button, which merges in main without a need for local actions. We try to avoid force-pushes since they make it harder to track the history of the PR. |
ZeroIntensity 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.
In general, this is looking pretty good! Several comments, though, as this is a pretty big PR.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Misc/NEWS.d/next/Core_and_Builtins/2024-11-04-21-58-20.gh-issue-125038.kGhWOS.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
ZeroIntensity 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.
Thank you! I think this is ready for a core dev to review it.@JelleZijlstra, would you mind taking a look?
markshannon commentedNov 12, 2024
I thought the idea was to entirely remove the I realize that would be a slight change, but it makes generator expressions behave the same as generators: >>>defmake_gen(x):...foriinx:...yieldi...>>>gen=make_gen(1)# No error here>>>next(gen)Traceback (mostrecentcalllast):File"<python-input-28>",line1,in<module>next(gen)~~~~^^^^^File"<python-input-26>",line2,inmake_genforiinx:^TypeError:'int'objectisnotiterable Creating a generator with a non-iterable is fine. It is only we try to iterate over it, that an error occurs. |
efimov-mikhail commentedNov 12, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
It's not possible to check arguments of an arbitrary generators, since it can be of any type. defmake_range_gen(n,m):foriinrange(n+m*5):yieldi But generator expressions can have only one parameter, which should be Let's look at the solution with
Cons:
I'm not sure about the balance of this pros and cons for the typical user of Python. @ZeroIntensity,@JelleZijlstra, what do you think? |
sobolevn commentedNov 13, 2024
Can we please discuss this a bit more? I don't think that changing where the error happens is safe in terms of backward compatibility. I am 100% sure that people expect error to happen when the gen is created and I am also sure that the code reflects that (validation, error handling, etc). If we are going to break this - we need to issue a deprecation period. I also don't fully understand why we are doing this. |
Sorry, there's enough contention here that I'd like to have my check removed from the PR (it was only supposed to denote "ready for core review," anyway).
efimov-mikhail commentedApr 12, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
It seems that this PR can be closed because other PR on this topic (#132351) is already merged. |
Uh oh!
There was an error while loading.Please reload this page.
Adds
CHECK_ITERABLEinstruction. It checks thatTOSis iterable or async iterable.IMO, new simple instruction is a good way to prevent behavior changes.
Redundant
GET_ITERinstructions are removed from generator expression code.Those were added during previous fix.
📚 Documentation preview 📚:https://cpython-previews--126408.org.readthedocs.build/