From 8187c828f7d0ee44cba3e22d24ac48f2c882560c Mon Sep 17 00:00:00 2001 From: A5rocks Date: Sat, 22 Aug 2026 00:36:07 -0400 Subject: [PATCH 1/2] Don't error unnecessarily about new syntax --- mypy/fastparse.py | 8 +++++--- mypy/test/data.py | 10 ++++++++-- test-data/unit/check-inline-config.test | 7 +++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/mypy/fastparse.py b/mypy/fastparse.py index d9e2d5df8f4c1..b3e54d0da7943 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -206,13 +206,15 @@ def parse( options = Options() errors.set_file(fnam, module, options=options) is_stub_file = fnam.endswith(".pyi") - if is_stub_file: + if ignore_errors: + feature_version = sys.version_info[1] + elif is_stub_file: feature_version = defaults.PYTHON3_VERSION[1] - if options.python_version[0] == 3 and options.python_version[1] > feature_version: - feature_version = options.python_version[1] else: assert options.python_version[0] >= 3 feature_version = options.python_version[1] + if options.python_version[0] == 3 and options.python_version[1] > feature_version: + feature_version = options.python_version[1] try: # Disable # - deprecation warnings for 'invalid escape sequence' (Python 3.11 and below) diff --git a/mypy/test/data.py b/mypy/test/data.py index 30e4ef95adc85..f406b0801db29 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -158,8 +158,8 @@ def _item_fail(msg: str) -> NoReturn: for arg in args: if arg.startswith("version"): compare_op = arg[7:9] - if compare_op not in {">=", "=="}: - _item_fail("Only >= and == version checks are currently supported") + if compare_op not in {">=", "==", "< "}: + _item_fail("Only `>=', `==', and `< ' version checks are currently supported") version_str = arg[9:] try: version = tuple(int(x) for x in version_str.split(".")) @@ -181,6 +181,12 @@ def _item_fail(msg: str) -> NoReturn: f'Only minor or patch version checks are currently supported with "==": {version_str!r}' ) version_check = sys.version_info[: len(version)] == version + elif compare_op == "< ": + if version < defaults.PYTHON3_VERSION: + _item_fail( + f"{arg} always false since minimum runtime version is {defaults.PYTHON3_VERSION}" + ) + version_check = sys.version_info < version if version_check: tmp_output = [expand_variables(line) for line in item.data] if os.path.sep == "\\" and case.normalize_output: diff --git a/test-data/unit/check-inline-config.test b/test-data/unit/check-inline-config.test index 8ada54a06b48c..80949c60a291b 100644 --- a/test-data/unit/check-inline-config.test +++ b/test-data/unit/check-inline-config.test @@ -475,3 +475,10 @@ x = 1 # type: ignore # E: Unused "type: ignore" comment x = 1 # type: ignore # E: Unused "type: ignore" comment [out] main:2: error: Unrecognized option: amongus = True + +[case testNewSyntaxOldMypy] +# flags: --python-version 3.10 +# mypy: ignore-errors=True +x = t"" +[out version< 3.14] +main:3: error: Invalid syntax From 06c77b47829ca5e78727d173d4de1c99ffd6ac84 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 22 Aug 2026 05:25:33 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/test/data.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mypy/test/data.py b/mypy/test/data.py index f406b0801db29..989a39a0297b0 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -159,7 +159,9 @@ def _item_fail(msg: str) -> NoReturn: if arg.startswith("version"): compare_op = arg[7:9] if compare_op not in {">=", "==", "< "}: - _item_fail("Only `>=', `==', and `< ' version checks are currently supported") + _item_fail( + "Only `>=', `==', and `< ' version checks are currently supported" + ) version_str = arg[9:] try: version = tuple(int(x) for x in version_str.split("."))