Skip to content

Commit 30a3c9e

Browse files
hauntsaninjax612skm
authored andcommitted
Disallow inline config of Python version (python#18497)
Fixes python#18450
1 parent 57bb663 commit 30a3c9e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

mypy/config_parser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ def parse_mypy_comments(
653653
# method is to create a config parser.
654654
parser = configparser.RawConfigParser()
655655
options, parse_errors = mypy_comments_to_config_map(line, template)
656+
657+
if "python_version" in options:
658+
errors.append((lineno, "python_version not supported in inline configuration"))
659+
del options["python_version"]
660+
656661
parser["dummy"] = options
657662
errors.extend((lineno, x) for x in parse_errors)
658663

test-data/unit/check-inline-config.test

Lines changed: 4 additions & 0 deletions
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)