Skip to content

Commit

Permalink
Disallow inline config of Python version (#18497)
Browse files Browse the repository at this point in the history
Fixes #18450
hauntsaninja authored Jan 25, 2025
1 parent 0c60548 commit 48d888a
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mypy/config_parser.py
Original file line number Diff line number Diff line change
@@ -647,6 +647,11 @@ def parse_mypy_comments(
# method is to create a config parser.
parser = configparser.RawConfigParser()
options, parse_errors = mypy_comments_to_config_map(line, template)

if "python_version" in options:
errors.append((lineno, "python_version not supported in inline configuration"))
del options["python_version"]

parser["dummy"] = options
errors.extend((lineno, x) for x in parse_errors)

4 changes: 4 additions & 0 deletions test-data/unit/check-inline-config.test
Original file line number Diff line number Diff line change
@@ -323,3 +323,7 @@ class Foo:
foo = Foo()
if foo: ...
42 + "no" # type: ignore


[case testInlinePythonVersion]
# mypy: python-version=3.10 # E: python_version not supported in inline configuration

0 comments on commit 48d888a

Please sign in to comment.