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
constant folding affects annotations despite 'from __future__ import annotations' #83401
Comments
PEP-563 interacts in weird ways with constant folding. running the following code:
I would expect this output:
But I get:
|
Łukasz, should we disable AST optimizations in annotations if "from __future__ import annotations" is used? |
Yo be honest, this would add a lot of complexity as "from __future__ import annotations" is a compiler directive (CO_FUTURE_ANNOTATIONS) and bringing this to the AST level would be somehow disrupting. I would be -1 to disable AST optimizations in annotations. |
I don't have a particularly deep opinion on what should be done, just a bit of weirdness I hit upon while implementing the PEP in PyPy. fwiw, we implement it as an AST transformer that the compiler runs before running the optimizer to make sure that the AST optimizations don't get applied to annotions. The transformer replaces all annotations with a Constant ast node, containing the unparsed string. |
I have given it a try in PR 17866 and it was not as invasive as I imagine, so if Łukasz agrees, we can go ahead :) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: