From e313371f6ae099f200c1f53e8e8bdc473ead827e Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Mon, 20 Jan 2025 23:56:30 -0800 Subject: [PATCH 1/2] Disallow inline config of Python version Fixes #18450 --- mypy/config_parser.py | 5 +++++ 1 file changed, 5 insertions(+) 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) From b60abf3e1706c09d9b7649dd87181bdbab4a18d1 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Fri, 24 Jan 2025 18:46:21 -0800 Subject: [PATCH 2/2] add test --- test-data/unit/check-inline-config.test | 4 ++++ 1 file changed, 4 insertions(+) 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