You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Compilation emits multiple warnings in the finally block #131927
Yet another option is to leave ast_opt alone, and handle this in the repl. So the repl would save the warnings from the ast construction and then filter out duplicated warnings from the compilation call.
#139642 and #139719 are two alternative solutions. The former makes ast.parse() not emitting warnings. The simply silences it in the REPR (the original solution by @tomasr8). It may be incomplete because we may need to silence warnings in other places of the stdlib, not mention a third-party code.
@serhiy-storchaka Based on the discussion in #139640, I posted an approving review on #139642, so I think we can close #139719 in favour of the more straightforward (and comprehensive) solution.
Activity
iritkatriel commentedon Mar 31, 2025
Possibly, particularly if we can add it as an internal option (i.e., not expose it via the documented API).
iritkatriel commentedon Mar 31, 2025
Yet another option is to leave ast_opt alone, and handle this in the repl. So the repl would save the warnings from the ast construction and then filter out duplicated warnings from the compilation call.
tomasr8 commentedon Mar 31, 2025
I like the last option the best since I'd also like to avoid touching ast_opt for this.
serhiy-storchaka commentedon Apr 8, 2025
We have the same issue in 3.12:
serhiy-storchaka commentedon Apr 8, 2025
It has no relation to REPL, it can be reproduced with
compile().[-]PEP 765 produces two warnings in the new REPL[/-][+]Compilation emits multiple warnings in the finally block[/+]tomasr8 commentedon Apr 8, 2025
Just adding a link here to my comment explaining why the warning is emitted more than once: #131993 (comment)
The tl;dr is that
_PyErr_EmitSyntaxWarningbypasses the warning registry. As a consequence, the warnings are not deduplicated.iritkatriel commentedon Apr 8, 2025
That looks like a different issue related to assert.
Try this:
gh-131927: Prevent emitting optimizer warnings twice in the REPL (#13…
serhiy-storchaka commentedon Apr 12, 2025
There were at least three different bugs:
finallyblock could emit two warnings, because the code in thefinallyblock is compiled twice.compile()calls emitted repeated warnings.The PR fixed them all. Maybe backport it, as the first two issues are old?
[3.13] pythongh-131927: Prevent emitting optimizer warnings twice in …
[3.13] pythongh-131927: Prevent emitting optimizer warnings twice in …
[3.13] pythongh-131927: Prevent emitting optimizer warnings twice in …
[3.13] gh-131927: Prevent emitting compiler warnings twice (GH-131993) (
serhiy-storchaka commentedon Oct 6, 2025
I realized that this was incorrect solution. See #139640.
serhiy-storchaka commentedon Oct 14, 2025
#139642 and #139719 are two alternative solutions. The former makes
ast.parse()not emitting warnings. The simply silences it in the REPR (the original solution by @tomasr8). It may be incomplete because we may need to silence warnings in other places of the stdlib, not mention a third-party code.ncoghlan commentedon Oct 29, 2025
@serhiy-storchaka Based on the discussion in #139640, I posted an approving review on #139642, so I think we can close #139719 in favour of the more straightforward (and comprehensive) solution.
gh-131927: Do not emit PEP 765 warnings in ast.parse() (GH-139642)
pythongh-131927: Do not emit PEP 765 warnings in ast.parse() (pythonG…
[3.14] gh-131927: Do not emit PEP 765 warnings in ast.parse() (GH-139642
pythongh-131927: Do not emit PEP 765 warnings in ast.parse() (pythonG…