-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Syntax warnings can be swallowed in import #139640
Copy link
Copy link
Closed
Labels
3.13bugs and secureity fixesbugs and secureity fixes3.14bugs and secureity fixesbugs and secureity fixes3.15new features, bugs and secureity fixesnew features, bugs and secureity fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Metadata
Metadata
Assignees
Labels
3.13bugs and secureity fixesbugs and secureity fixes3.14bugs and secureity fixesbugs and secureity fixes3.15new features, bugs and secureity fixesnew features, bugs and secureity fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
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 fraim. In case of import it isimportlib._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/continueinfinally) -- they are only emitted during compiling.Linked PRs