-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
gh-116767: fix crash on 'async with' with many context managers #118348
Conversation
Thank you! I can't say I follow all of what's happening here, but I have a better picture now :) This is technically backwards incompatible -- the limit is decreased even for plain async def t():
with c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c: c
def g():
with c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c,c: yield Should |
We could, though this maximum static depth is not documented anywhere and I seriously doubt anyone hits it. |
I made the change, it changes semantics the other way (allowing one more nested level in the non-generator case). I think that's ok. (The compiler could distinguish the cases and use a different limit for each, but I don't think it's worth the added complexity). |
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 guess the kind of use-case that would hit this is auto-generated code. Bumping to 21 is easier than researching if someone does that.
Thanks @iritkatriel for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Sorry, @iritkatriel and @encukou, I could not cleanly backport this to
|
|
…pythonGH-118348) Account for `add_stopiteration_handler` pushing a block for `async with`. To allow generator functions that previously almost hit the `CO_MAXBLOCKS` limit by nesting non-async blocks, the limit is increased by 1. This increase allows one more block in non-generator functions. (cherry picked from commit c1bf487)
GH-118477 is a backport of this pull request to the 3.12 branch. |
GH-118348) (#118477) gh-116767: fix crash on 'async with' with many context managers (GH-118348) Account for `add_stopiteration_handler` pushing a block for `async with`. To allow generator functions that previously almost hit the `CO_MAXBLOCKS` limit by nesting non-async blocks, the limit is increased by 1. This increase allows one more block in non-generator functions. (cherry picked from commit c1bf487)
…pythonGH-118348) Account for `add_stopiteration_handler` pushing a block for `async with`. To allow generator functions that previously almost hit the `CO_MAXBLOCKS` limit by nesting non-async blocks, the limit is increased by 1. This increase allows one more block in non-generator functions.
Fixes #116767.