GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||
GeezerVison is showing github.com — gh-131927: Do not emit PEP 765 warnings in ast.parse() by serhiy-storchaka · Pull Request #139642 · python/cpython Conversation
|
|
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.
There was an error while loading. Please reload this page.
|
Only if you are fine with double warnings in REPL or other places that use There are three kinds of warnings, by the emitter:
So, you already see not all warnings if you only use |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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.
There was an error while loading. Please reload this page.
|
We can, but
It is safer to disable that warning by default in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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.
There was an error while loading. Please reload this page.
|
What is the name of the option you propose to add? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Could be |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
No, because it should not control all warnings. Maybe |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This would complicated, and I need to revert #131993 because it is a blocker for my other changes. See yet one option in #139719. It is based on the original solution by @tomasr8. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Why not all warnings? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
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 was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There are three kinds of warnings. #139642 (comment) If we silence all warnings in 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.
There was an error while loading. Please reload this page.
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 an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…H-139642) ast.parse() no longer emits syntax warnings for return/break/continue in finally (see PEP-765) -- they are only emitted during compilation. (cherry picked from commit ad0a3f7) Co-authored-by: Serhiy Storchaka <[email protected]>
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-140786 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thank you for review. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
) (GH-140786) ast.parse() no longer emits syntax warnings for return/break/continue in finally (see PEP-765) -- they are only emitted during compilation. (cherry picked from commit ad0a3f7) Co-authored-by: Serhiy Storchaka <[email protected]>
…H-139642) ast.parse() no longer emits syntax warnings for return/break/continue in finally (see PEP-765) -- they are only emitted during compilation.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.