-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
gh-135801: Improve filtering by module in warn_explicit() without module argument #140151
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
f37f14c
bc5981e
4763a74
9cbe5ea
638baca
a359dda
67b7fb9
c0b9a69
7751a6c
bc60e60
9ce17e4
b473aa9
7510f2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1088,6 +1088,28 @@ def four_freevars(): | |
| three_freevars.__globals__, | ||
| closure=my_closure) | ||
|
|
||
| def test_exec_filter_syntax_warnings_by_module(self): | ||
| filename = support.findfile('test_import/data/syntax_warnings.py') | ||
| with open(filename, 'rb') as f: | ||
| source = f.read() | ||
| with warnings.catch_warnings(record=True) as wlog: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may use a loop since the code is basically duplicated. Something like:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of tests (except |
||
| warnings.simplefilter('error') | ||
| warnings.filterwarnings('always', module=r'<string>\z') | ||
| exec(source, {}) | ||
| self.assertEqual(sorted(wm.lineno for wm in wlog), [4, 7, 10, 13, 14, 21]) | ||
| for wm in wlog: | ||
| self.assertEqual(wm.filename, '<string>') | ||
| self.assertIs(wm.category, SyntaxWarning) | ||
|
|
||
| with warnings.catch_warnings(record=True) as wlog: | ||
| warnings.simplefilter('error') | ||
| warnings.filterwarnings('always', module=r'<string>\z') | ||
| exec(source, {'__name__': 'package.module', '__file__': filename}) | ||
| self.assertEqual(sorted(wm.lineno for wm in wlog), [4, 7, 10, 13, 14, 21]) | ||
| for wm in wlog: | ||
| self.assertEqual(wm.filename, '<string>') | ||
| self.assertIs(wm.category, SyntaxWarning) | ||
|
|
||
|
|
||
| def test_filter(self): | ||
| self.assertEqual(list(filter(lambda c: 'a' <= c <= 'z', 'Hello World')), list('elloorld')) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Syntax warnings emitted in different parts of the Python compiler. | ||
|
|
||
| # Parser/lexer/lexer.c | ||
| x = 1or 0 # line 4 | ||
|
|
||
| # Parser/tokenizer/helpers.c | ||
| '\z' # line 7 | ||
|
|
||
| # Parser/string_parser.c | ||
| '\400' # line 10 | ||
|
|
||
| # _PyCompile_Warn() in Python/codegen.c | ||
| assert(x, 'message') # line 13 | ||
| x is 1 # line 14 | ||
|
|
||
| # _PyErr_EmitSyntaxWarning() in Python/ast_preprocess.c | ||
| def f(): | ||
| try: | ||
| pass | ||
| finally: | ||
| return 42 # line 21 |
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.
\__init__.pywis supported on Windows, you can do something like: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.
Hmm, I was too lazy to check and mistakenly supposed that
.pywis not supported for__init__. But I just checked -- indeed, it works.