Skip to content
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

gh-103492: Clarify SyntaxWarning with literal comparison #103493

Merged
merged 10 commits into from
Apr 24, 2023
Prev Previous commit
Next Next commit
simplify warning code (tested with and without -W error)
hauntsaninja committed Apr 20, 2023

Unverified

This user has not yet uploaded their public signing key.
commit 8f16b1a6fa9fa7b7f307d8eb6cbac49cb8dc653f
7 changes: 2 additions & 5 deletions Lib/test/test_grammar.py
Original file line number Diff line number Diff line change
@@ -236,12 +236,9 @@ def check(test, error=False):
check(f"[{num}for x in ()]")
check(f"{num}spam", error=True)

with self.assertWarnsRegex(SyntaxWarning, r'invalid \w+ literal'):
compile(f"{num}is x", "<testcase>", "eval")
with warnings.catch_warnings():
warnings.filterwarnings('ignore', '"is" with int literal',
SyntaxWarning)
with self.assertWarnsRegex(SyntaxWarning,
r'invalid \w+ literal'):
compile(f"{num}is x", "<testcase>", "eval")
warnings.simplefilter('error', SyntaxWarning)
with self.assertRaisesRegex(SyntaxError,
r'invalid \w+ literal'):