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..989a39a0297b0 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -158,8 +158,10 @@ 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 +183,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