Skip to content

Syntax warnings can be swallowed in import #139640

@serhiy-storchaka

Description

@serhiy-storchaka

Bug report

As I worked on issue #135801, I realized that the solution to issue #131927 was wrong. _PyErr_WarnExplicitObjectWithContext() takes the module name and the warning registry from the current Python frame. In case of import it is importlib._bootstrap_external.

Wrong module name which makes difficult to filter syntax warnings is an old issue, but the main problem is that syntax warnings for imported modules share the same warning registry. When you import two modules why by accident emit the same syntax warning at the same line number, you will only see one warning by default. It may be argued that swallowing a warning is worse that emitting a warning twice.

The following PR reverts PR #131993 and provides an alternative solution that fixes all double warnings but keeps warnings for repeated compilation. ast.parse() no longer emits warnings that are emitted in the AST optimizer (return/break/continue in finally) -- they are only emitted during compiling.

Linked PRs

Metadata

Metadata

Labels

3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions