Skip to content
Merged
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
2 changes: 2 additions & 0 deletions mypy/test/testparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
def test_parse_error(testcase: DataDrivenTestCase) -> None:
try:
options = parse_options("\n".join(testcase.input), testcase, 0)
if options.python_version < defaults.PYTHON3_VERSION:
options.python_version = defaults.PYTHON3_VERSION
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be impossible? The options should default to sys.version_info and at very worst this should trigger?

Copy link
Collaborator Author

@hauntsaninja hauntsaninja Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there is other test-specific code that sets it to defaults.PYTHON3_VERSION_MIN (which is lower than PYTHON3_VERSION). Grep for testfile_pyversion

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah oops, I actually misread that (as only referring to defaults.PYTHON3_VERSION, oops).

Thanks! Makes sense.

if options.python_version != sys.version_info[:2]:
skip()
# Compile temporary file. The test file contains non-ASCII characters.
Expand Down
20 changes: 10 additions & 10 deletions test-data/unit/parse-errors.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def f()
pass
[out]
file:1: error: Invalid syntax
file:1: error: Expected ':'

[case testUnexpectedIndent]
1
Expand Down Expand Up @@ -55,7 +55,7 @@ file:1: error: Invalid syntax
[case testUnexpectedEof]
if 1:
[out]
file:1: error: Expected an indented block
file:1: error: Expected an indented block after 'if' statement on line 1

[case testInvalidKeywordArguments1]
f(x=y, z)
Expand Down Expand Up @@ -281,17 +281,17 @@ file:3: error: Inconsistent use of "**" in function signature
[case testPrintStatementInPython3]
print 1
[out]
file:1: error: Missing parentheses in call to 'print'. Did you mean print(1)?
file:1: error: Missing parentheses in call to 'print'. Did you mean print(...)?

[case testInvalidConditionInConditionalExpression]
1 if 2, 3 else 4
[out]
file:1: error: Invalid syntax
file:1: error: Expected 'else' after 'if' expression

[case testInvalidConditionInConditionalExpression2]
1 if x for y in z else 4
[out]
file:1: error: Invalid syntax
file:1: error: Expected 'else' after 'if' expression

[case testInvalidConditionInConditionalExpression3]
1 if x else for y in z
Expand Down Expand Up @@ -360,17 +360,17 @@ file:1: error: Invalid syntax
[case testParseErrorInExtendedSlicing]
x[:,
[out]
file:1: error: Unexpected EOF while parsing
file:1: error: '[' was never closed

[case testParseErrorInExtendedSlicing2]
x[:,::
[out]
file:1: error: Unexpected EOF while parsing
file:1: error: '[' was never closed

[case testParseErrorInExtendedSlicing3]
x[:,:
[out]
file:1: error: Unexpected EOF while parsing
file:1: error: '[' was never closed

[case testInvalidEncoding]
# foo
Expand Down Expand Up @@ -407,7 +407,7 @@ file:0: error: Unknown encoding: uft8
2L
0x2L
[out]
file:1: error: Invalid syntax
file:1: error: Invalid decimal literal

[case testPython2LegacyInequalityInPython3]
1 <> 2
Expand Down Expand Up @@ -440,4 +440,4 @@ try:
except KeyError, IndexError:
pass
[out]
file:3: error: Invalid syntax
file:3: error: Multiple exception types must be parenthesized
Loading