Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-131927: Do not emit PEP 765 warnings in ast.parse()#139642
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
gh-131927: Do not emit PEP 765 warnings in ast.parse()#139642
Uh oh!
There was an error while loading.Please reload this page.
Conversation
RevertpythonGH-131993.Fix swallowing some syntax warnings in different modules if they accidentallyhave the same message and are emitted from the same line.ast.parse() no longer emits syntax warnings forreturn/break/continue in finally (see PEP-765) -- they are onlyemitted during compilation.
2fa4266 toc04d874Compare
Eclips4 left a comment
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.
The AST changes are LGTM.
Thank you Serhiy.
ncoghlan commentedOct 7, 2025
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. |
serhiy-storchaka commentedOct 7, 2025
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 |
iritkatriel commentedOct 7, 2025
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? |
serhiy-storchaka commentedOct 7, 2025
We can, but
It is safer to disable that warning by default in |
iritkatriel commentedOct 7, 2025
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). |
serhiy-storchaka commentedOct 7, 2025
What is the name of the option you propose to add? |
iritkatriel commentedOct 7, 2025
Could be |
serhiy-storchaka commentedOct 7, 2025
No, because it should not control all warnings. Maybe |
serhiy-storchaka commentedOct 7, 2025
iritkatriel commentedOct 7, 2025
Why not all warnings? |
ncoghlan commentedOct 7, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The early PEP 765 warnings were indeed specified in the last paragraph ofhttps://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. |
serhiy-storchaka commentedOct 8, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There are three kinds of warnings.#139642 (comment) If we silenceall 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:
|
serhiy-storchaka commentedOct 8, 2025
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. |
ncoghlan left a comment
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.
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.
ad0a3f7 intopython:mainUh oh!
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,@serhiy-storchaka, I could not cleanly backport this to |
GH-140786 is a backport of this pull request to the3.14 branch. |
serhiy-storchaka commentedOct 30, 2025
Thank you for review. |
…H-139642)ast.parse() no longer emits syntax warnings forreturn/break/continue in finally (see PEP-765) -- they are onlyemitted during compilation.
Uh oh!
There was an error while loading.Please reload this page.
RevertGH-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 (seePEP-765) -- they are only emitted during compilation.