Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions mypy/test/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("."))
Expand All @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions test-data/unit/check-inline-config.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading