-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Do not blindly undefer on leaving fuction #18674
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
Hm, some of the new errors are truly bizarre, I will need to dig deeper in this. |
OK, so here is the analysis for
cc @JukkaL who initially implemented this feature. IIUC possible fix is to save/restore full binder stack when checking deferred functions. Alternatively we may consider only deferring top-level functions, instead of the nested ones. IMO performance impact from this will be small.
I remember fixing something similar for the daemon was a huge pain (and I am not even sure we fixed it completely, see e.g. |
This comment has been minimized.
This comment has been minimized.
If we defer nested functions, that sounds like a problem. I think we should only defer top-level functions. |
Yeah, seems reasonable. More than two passes should only be needed in very rare circumstances. |
@JukkaL OK, I will create two small PRs for these two, and probably merge them first. IIUC it should be safer that other way around. |
This helps in rare cases, see discussion in #18674
This makes deferral logic more robust and more consistent with fine-grained mode. I also: * Change some terminology, as "top function" is ambiguous: top-level function vs top of stack function. * Update some docs and type annotations to match actual behavior (e.g. we do not defer lambdas) See also #18674 for some more motivation.
Diff from mypy_primer, showing the effect of this PR on open source code: django-stubs (https://github.com/typeddjango/django-stubs)
discord.py (https://github.com/Rapptz/discord.py)
+ discord/shard.py:540: error: Cannot determine type of "_closing_task" [has-type]
+ discord/shard.py:541: error: Cannot determine type of "_closing_task" [has-type]
|
I decide also to put up #18723 (for |
Fixes #16496 for real.
The fix is trivial, just save and restore the previous value.