diff --git a/mypy/config_parser.py b/mypy/config_parser.py index a0f93f663522..76396168550c 100644 --- a/mypy/config_parser.py +++ b/mypy/config_parser.py @@ -608,6 +608,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) diff --git a/test-data/unit/check-inline-config.test b/test-data/unit/check-inline-config.test index bedba811d95b..c81dcac94afd 100644 --- a/test-data/unit/check-inline-config.test +++ b/test-data/unit/check-inline-config.test @@ -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