Skip to content

Suggest using a newer Python version if possibly needed #13197

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

Merged
merged 4 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ def parse(
options = Options()
errors.set_file(fnam, module)
is_stub_file = fnam.endswith(".pyi")
if is_stub_file:
feature_version = defaults.PYTHON3_VERSION[1]
else:
assert options.python_version[0] >= 3
feature_version = options.python_version[1]
try:
if is_stub_file:
feature_version = defaults.PYTHON3_VERSION[1]
else:
assert options.python_version[0] >= 3
feature_version = options.python_version[1]
# Disable deprecation warnings about \u
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)
Expand All @@ -294,10 +294,14 @@ def parse(
# start of the f-string. This would be misleading, as mypy will report the error as the
# lineno within the file.
e.lineno = None
message = e.msg
if feature_version > sys.version_info.minor and message.startswith("invalid syntax"):
python_version_str = f"{options.python_version[0]}.{options.python_version[1]}"
message += f"; you likely need to run mypy using Python {python_version_str} or newer"
errors.report(
e.lineno if e.lineno is not None else -1,
e.offset,
e.msg,
message,
blocker=True,
code=codes.SYNTAX,
)
Expand Down
6 changes: 6 additions & 0 deletions test-data/unit/check-newsyntax.test
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,9 @@ v = 1
reveal_type(f'{v}') # N: Revealed type is "builtins.str"
reveal_type(f'{1}') # N: Revealed type is "builtins.str"
[builtins fixtures/f_string.pyi]

[case testFeatureVersionSuggestion]
# flags: --python-version 3.99
this is what future python looks like public static void main String[] args await goto exit
[out]
main:2: error: invalid syntax; you likely need to run mypy using Python 3.99 or newer