| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -84,9 +84,11 @@ def _maybe_compile(compiler, source, filename, symbol): | |||
| 84 | 84 | except SyntaxError: | |
| 85 | 85 | pass | |
| 86 | 86 | ||
| 87 | - # Suppress warnings after the first compile to avoid duplication. | ||
| 87 | + # Catch syntax warnings after the first compile | ||
| 88 | + # to emit SyntaxWarning at most once. | ||
| 88 | 89 | with warnings.catch_warnings(): | |
| 89 | - warnings.simplefilter("ignore") | ||
| 90 | + warnings.simplefilter("error", SyntaxWarning) | ||
| 91 | + | ||
| 90 | 92 | try: | |
| 91 | 93 | code1 = compiler(source + "\n", filename, symbol) | |
| 92 | 94 | except SyntaxError as e: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | """ | |
| 5 | 5 | import sys | |
| 6 | 6 | import unittest | |
| 7 | + import warnings | ||
| 7 | 8 | from test import support | |
| 8 | 9 | from test.support import warnings_helper | |
| 9 | 10 | ||
@@ -310,5 +311,11 @@ def test_warning(self): | |||
| 310 | 311 | compile_command("0 is 0") | |
| 311 | 312 | self.assertEqual(len(w.warnings), 1) | |
| 312 | 313 | ||
| 314 | + # bpo-41520: check SyntaxWarning treated as an SyntaxError | ||
| 315 | + with self.assertRaises(SyntaxError): | ||
| 316 | + warnings.simplefilter('error', SyntaxWarning) | ||
| 317 | + compile_command('1 is 1\n', symbol='exec') | ||
| 318 | + | ||
| 319 | + | ||
| 313 | 320 | if __name__ == "__main__": | |
| 314 | 321 | unittest.main() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Fix :mod:`codeop` regression: it no longer ignores :exc:`SyntaxWarning`. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments