Skip to content

Commit

Permalink
Allow stubs to use newer syntax than 3.7 (#13500)
Browse files Browse the repository at this point in the history
Fixes #13499

Today this code reads like "stubs should all target 3.7" and this
is indeed how typeshed operates. But authors of pyi other than typeshed
should probably be allowed to choose what Python version they're
targetting. Since typeshed runs checks against 3.7, this should not
cause testing regressions for typeshed.

This code goes back to #3000 back in the typed_ast days, when this
allowed stubs to use much newer syntax features than the base Python
version, so in some ways this is in the spirit of the original code.
  • Loading branch information
hauntsaninja authored Aug 24, 2022
1 parent 1f308e9 commit 09b0fa4
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ def parse(
is_stub_file = fnam.endswith(".pyi")
if is_stub_file:
feature_version = defaults.PYTHON3_VERSION[1]
if options.python_version[0] == 3 and options.python_version[1] > feature_version:
feature_version = options.python_version[1]
else:
assert options.python_version[0] >= 3
feature_version = options.python_version[1]
Expand Down

0 comments on commit 09b0fa4

Please sign in to comment.