| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Revert pythonGH-131993. Fix swallowing some syntax warnings in different modules if they accidentally have the same message and are emitted from the same line. ast.parse() no longer emits syntax warnings for return/break/continue in finally (see PEP-765) -- they are only emitted during compilation.
There was a problem hiding this comment.
The AST changes are LGTM.
Thank you Serhiy.
Sorry, something went wrong.
|
Would it be possible to avoid the side effect of delaying the PEP 765 syntax warnings to the code generation stage? Emitting those syntax warnings during AST construction is one of the key reasons I was comfortable suggesting turning them off globally in #139658 when static code analysis was in use. |
Sorry, something went wrong.
|
Only if you are fine with double warnings in REPL or other places that use ast.parse() + compile() instead of just compile(). There are three kinds of warnings, by the emitter:
So, you already see not all warnings if you only use ast.parse(), without code generation. The fact that the PEP 765 warnings are emitted in the AST optimizer instead of the code generator is just an implementation detail. It could perhaps even be more convenient to emit them in the code generator. |
Sorry, something went wrong.
Actually I think this was a deliberate decision, we want this to happen during static analysis. Can we add a kwarg to ast.parse to tell it whether to emit syntax warnings or not? |
Sorry, something went wrong.
|
We can, but
It is safer to disable that warning by default in ast.parse(). |
Sorry, something went wrong.
The default should be to give the warning. Turn it off in cpython when we know that the code was just ast.parse'ed (rather than an ast given by the user - we do know that). |
Sorry, something went wrong.
|
What is the name of the option you propose to add? |
Sorry, something went wrong.
|
Could be with_warnings or something like that. |
Sorry, something went wrong.
|
No, because it should not control all warnings. Maybe _enable_pep_765_warnings? |
Sorry, something went wrong.
|
Why not all warnings? |
Sorry, something went wrong.
|
The early PEP 765 warnings were indeed specified in the last paragraph of https://peps.python.org/pep-0765/#specification Edit: that said, I'm open to revisiting that decision and instead letting linters make the call on how to present syntax warnings in their ruleset. My suspicion is that they would end up turning off the parse-time warnings anyway, in which case we don't actually lose anything important by handling the PEP 765 warnings in the code generation step instead of the AST parsing step. |
Sorry, something went wrong.
There are three kinds of warnings. #139642 (comment) If we silence all warnings in ast.parse() or compile(), we will silence not only the PEP 765 warnings, but also warnings emitted in the tokenizer or in the code generator. Anyway, adding an option for selective silencing requires complex changes will be a complex change comparable to #139652, but with less benefit. I would rather not backport it to 3.14. So we have a choice for 3.14:
|
Sorry, something went wrong.
This contrasts AST construction and execution of pre-compiled code. But there is a missed step -- the code generation from AST. You cannot normally execute AST. |
Sorry, something went wrong.
There was a problem hiding this comment.
As per discussion at #139640 (comment), @iritkatriel and I both agree that given the unforeseen consequences of emitting the PEP 765 syntax warnings early, it makes the most sense to resolve this problem by emitting them in the opcode generation step alongside most of the other syntax warnings.
Sorry, something went wrong.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Sorry, something went wrong.
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict. cherry_picker ad0a3f733b23e7fc69aff13055c7fac8ab9dcd66 3.13 |
Sorry, something went wrong.
|
GH-140786 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
|
Thank you for review. |
Sorry, something went wrong.
…H-139642) ast.parse() no longer emits syntax warnings for return/break/continue in finally (see PEP-765) -- they are only emitted during compilation.
| Back | FazBrowse Home | New Git URL |
Revert GH-131993.
Fix swallowing some syntax warnings in different modules if they accidentally have the same message and are emitted from the same line.
ast.parse() no longer emits syntax warnings for
return/break/continue in finally (see PEP-765) -- they are only emitted during compilation.