Skip to content

Commit 4ff1830

Browse files
authored
Filter SyntaxWarnings during AST parsing (#20023)
Especially with [PEP 765](https://peps.python.org/pep-0765/) in 3.14, Python has been getting more liberal in emitting SyntaxWarnings during AST parsing and compilation. Generally, they aren't really helpful for mypy itself. There are open discussions to add a flag which would disable these. Until that's implemented, filter the warnings manually. _This also get's rid of the warnings emitted on test code. If at some point `return in finally` will be made an error, those tests could be adjust / removed. Until then, we can continue to test these as is without issues._ ```py def func() -> None: try: x = 1/0 finally: return None # return in finally "Hello \P world" # invalid escape sequence "" is 1 # "is" with 'int' literal ```
1 parent f2ebd79 commit 4ff1830

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

mypy/fastparse.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,12 @@ def parse(
232232
assert options.python_version[0] >= 3
233233
feature_version = options.python_version[1]
234234
try:
235-
# Disable deprecation warnings about \u
235+
# Disable
236+
# - deprecation warnings about \u
237+
# - syntax warnings for 'invalid escape sequence' (3.12+) and 'return in finally' (3.14+)
236238
with warnings.catch_warnings():
237239
warnings.filterwarnings("ignore", category=DeprecationWarning)
240+
warnings.filterwarnings("ignore", category=SyntaxWarning)
238241
ast = ast3_parse(source, fnam, "exec", feature_version=feature_version)
239242

240243
tree = ASTConverter(

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,6 @@ xfail_strict = true
227227
# Force warnings as errors
228228
filterwarnings = [
229229
"error",
230-
# Some testcases may contain code that emits SyntaxWarnings, and they are not yet
231-
# handled consistently in 3.14 (PEP 765)
232-
"default::SyntaxWarning",
233230
]
234231

235232
[tool.coverage.run]

0 commit comments

Comments
 (0)