Skip to content

Commit 48d888a

Browse files
authored
Disallow inline config of Python version (#18497)
Fixes #18450
1 parent 0c60548 commit 48d888a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

Diff for: mypy/config_parser.py

+5
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,11 @@ def parse_mypy_comments(
647647
# method is to create a config parser.
648648
parser = configparser.RawConfigParser()
649649
options, parse_errors = mypy_comments_to_config_map(line, template)
650+
651+
if "python_version" in options:
652+
errors.append((lineno, "python_version not supported in inline configuration"))
653+
del options["python_version"]
654+
650655
parser["dummy"] = options
651656
errors.extend((lineno, x) for x in parse_errors)
652657

Diff for: test-data/unit/check-inline-config.test

+4
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,7 @@ class Foo:
323323
foo = Foo()
324324
if foo: ...
325325
42 + "no" # type: ignore
326+
327+
328+
[case testInlinePythonVersion]
329+
# mypy: python-version=3.10 # E: python_version not supported in inline configuration

0 commit comments

Comments
 (0)