Skip to content

Commit b752e31

Browse files
Conformance tests: Update Never test (#1688)
1 parent e076b5c commit b752e31

File tree

5 files changed

+40
-71
lines changed

5 files changed

+40
-71
lines changed
Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
conformant = "Pass"
22
output = """
33
specialtypes_never.py:19: error: Implicit return in function which does not return [misc]
4-
specialtypes_never.py:85: error: Incompatible types in assignment (expression has type "list[NoReturn]", variable has type "list[int]") [assignment]
5-
specialtypes_never.py:85: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
6-
specialtypes_never.py:85: note: Consider using "Sequence" instead, which is covariant
7-
specialtypes_never.py:104: error: Incompatible return value type (got "ClassC[NoReturn]", expected "ClassC[U]") [return-value]
4+
specialtypes_never.py:82: error: Incompatible types in assignment (expression has type "list[NoReturn]", variable has type "list[int]") [assignment]
5+
specialtypes_never.py:82: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
6+
specialtypes_never.py:82: note: Consider using "Sequence" instead, which is covariant
7+
specialtypes_never.py:101: error: Incompatible return value type (got "ClassC[NoReturn]", expected "ClassC[U]") [return-value]
88
"""
9-
conformance_automated = "Fail"
9+
conformance_automated = "Pass"
1010
errors_diff = """
11-
Line 43: Expected 1 errors
12-
Line 45: Expected 1 errors
13-
Line 50: Expected 1 errors
14-
Line 51: Expected 1 errors
15-
Line 54: Expected 1 errors
16-
Line 59: Expected 1 errors
17-
Line 60: Expected 1 errors
1811
"""

conformance/results/pyre/specialtypes_never.toml

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,24 @@ Does not treat Never as compatible with all other types.
44
"""
55
output = """
66
specialtypes_never.py:21:8 Incompatible return type [7]: Function declared non-returnable, but got `None`.
7-
specialtypes_never.py:58:0 Uninitialized attribute [13]: Attribute `x` is declared in class `ClassA` to have type `NoReturn` but is never initialized.
8-
specialtypes_never.py:58:0 Uninitialized attribute [13]: Attribute `y` is declared in class `ClassA` to have type `typing.List[NoReturn]` but is never initialized.
9-
specialtypes_never.py:67:4 Incompatible variable type [9]: v1 is declared to have type `int` but is used as type `Never`.
10-
specialtypes_never.py:68:4 Incompatible variable type [9]: v2 is declared to have type `str` but is used as type `Never`.
11-
specialtypes_never.py:69:4 Incompatible variable type [9]: v3 is declared to have type `List[str]` but is used as type `Never`.
12-
specialtypes_never.py:85:4 Incompatible variable type [9]: v3 is declared to have type `List[int]` but is used as type `List[Never]`.
13-
specialtypes_never.py:86:4 Incompatible variable type [9]: v4 is declared to have type `Never` but is used as type `NoReturn`.
14-
specialtypes_never.py:95:4 Incompatible return type [7]: Expected `ClassB[Variable[U]]` but got `ClassB[Never]`.
15-
specialtypes_never.py:104:4 Incompatible return type [7]: Expected `ClassC[Variable[U]]` but got `ClassC[Never]`.
7+
specialtypes_never.py:55:0 Uninitialized attribute [13]: Attribute `x` is declared in class `ClassA` to have type `NoReturn` but is never initialized.
8+
specialtypes_never.py:55:0 Uninitialized attribute [13]: Attribute `y` is declared in class `ClassA` to have type `typing.List[NoReturn]` but is never initialized.
9+
specialtypes_never.py:64:4 Incompatible variable type [9]: v1 is declared to have type `int` but is used as type `Never`.
10+
specialtypes_never.py:65:4 Incompatible variable type [9]: v2 is declared to have type `str` but is used as type `Never`.
11+
specialtypes_never.py:66:4 Incompatible variable type [9]: v3 is declared to have type `List[str]` but is used as type `Never`.
12+
specialtypes_never.py:82:4 Incompatible variable type [9]: v3 is declared to have type `List[int]` but is used as type `List[Never]`.
13+
specialtypes_never.py:83:4 Incompatible variable type [9]: v4 is declared to have type `Never` but is used as type `NoReturn`.
14+
specialtypes_never.py:92:4 Incompatible return type [7]: Expected `ClassB[Variable[U]]` but got `ClassB[Never]`.
15+
specialtypes_never.py:101:4 Incompatible return type [7]: Expected `ClassC[Variable[U]]` but got `ClassC[Never]`.
1616
"""
1717
conformance_automated = "Fail"
1818
errors_diff = """
1919
Line 19: Expected 1 errors
20-
Line 43: Expected 1 errors
21-
Line 45: Expected 1 errors
22-
Line 50: Expected 1 errors
23-
Line 51: Expected 1 errors
24-
Line 54: Expected 1 errors
25-
Line 59: Expected 1 errors
26-
Line 60: Expected 1 errors
2720
Line 21: Unexpected errors ['specialtypes_never.py:21:8 Incompatible return type [7]: Function declared non-returnable, but got `None`.']
28-
Line 58: Unexpected errors ['specialtypes_never.py:58:0 Uninitialized attribute [13]: Attribute `x` is declared in class `ClassA` to have type `NoReturn` but is never initialized.', 'specialtypes_never.py:58:0 Uninitialized attribute [13]: Attribute `y` is declared in class `ClassA` to have type `typing.List[NoReturn]` but is never initialized.']
29-
Line 67: Unexpected errors ['specialtypes_never.py:67:4 Incompatible variable type [9]: v1 is declared to have type `int` but is used as type `Never`.']
30-
Line 68: Unexpected errors ['specialtypes_never.py:68:4 Incompatible variable type [9]: v2 is declared to have type `str` but is used as type `Never`.']
31-
Line 69: Unexpected errors ['specialtypes_never.py:69:4 Incompatible variable type [9]: v3 is declared to have type `List[str]` but is used as type `Never`.']
32-
Line 86: Unexpected errors ['specialtypes_never.py:86:4 Incompatible variable type [9]: v4 is declared to have type `Never` but is used as type `NoReturn`.']
33-
Line 95: Unexpected errors ['specialtypes_never.py:95:4 Incompatible return type [7]: Expected `ClassB[Variable[U]]` but got `ClassB[Never]`.']
21+
Line 55: Unexpected errors ['specialtypes_never.py:55:0 Uninitialized attribute [13]: Attribute `x` is declared in class `ClassA` to have type `NoReturn` but is never initialized.', 'specialtypes_never.py:55:0 Uninitialized attribute [13]: Attribute `y` is declared in class `ClassA` to have type `typing.List[NoReturn]` but is never initialized.']
22+
Line 64: Unexpected errors ['specialtypes_never.py:64:4 Incompatible variable type [9]: v1 is declared to have type `int` but is used as type `Never`.']
23+
Line 65: Unexpected errors ['specialtypes_never.py:65:4 Incompatible variable type [9]: v2 is declared to have type `str` but is used as type `Never`.']
24+
Line 66: Unexpected errors ['specialtypes_never.py:66:4 Incompatible variable type [9]: v3 is declared to have type `List[str]` but is used as type `Never`.']
25+
Line 83: Unexpected errors ['specialtypes_never.py:83:4 Incompatible variable type [9]: v4 is declared to have type `Never` but is used as type `NoReturn`.']
26+
Line 92: Unexpected errors ['specialtypes_never.py:92:4 Incompatible return type [7]: Expected `ClassB[Variable[U]]` but got `ClassB[Never]`.']
3427
"""
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
conformant = "Pass"
22
output = """
33
specialtypes_never.py:19:22 - error: Function with declared return type "NoReturn" cannot return "None" (reportReturnType)
4-
specialtypes_never.py:85:21 - error: Expression of type "list[Never]" cannot be assigned to declared type "list[int]"
4+
specialtypes_never.py:82:21 - error: Expression of type "list[Never]" cannot be assigned to declared type "list[int]"
55
  "list[Never]" is incompatible with "list[int]"
66
    Type parameter "_T@list" is invariant, but "Never" is not the same as "int"
77
    Consider switching from "list" to "Sequence" which is covariant (reportAssignmentType)
8-
specialtypes_never.py:104:12 - error: Expression of type "ClassC[Never]" cannot be assigned to return type "ClassC[U@func10]"
8+
specialtypes_never.py:101:12 - error: Expression of type "ClassC[Never]" cannot be assigned to return type "ClassC[U@func10]"
99
  "ClassC[Never]" is incompatible with "ClassC[U@func10]"
1010
    Type parameter "T@ClassC" is invariant, but "Never" is not the same as "U@func10" (reportReturnType)
1111
"""
12-
conformance_automated = "Fail"
12+
conformance_automated = "Pass"
1313
errors_diff = """
14-
Line 43: Expected 1 errors
15-
Line 45: Expected 1 errors
16-
Line 50: Expected 1 errors
17-
Line 51: Expected 1 errors
18-
Line 54: Expected 1 errors
19-
Line 59: Expected 1 errors
20-
Line 60: Expected 1 errors
2114
"""

conformance/results/pytype/specialtypes_never.toml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,18 @@ Does not understand NoReturn or Never.
55
output = """
66
File "specialtypes_never.py", line 11, in <module>: argument "covariant" to TypeVar not supported yet [not-supported-yet]
77
File "specialtypes_never.py", line 21, in func1: bad return type [bad-return-type]
8-
File "specialtypes_never.py", line 67, in func6: Type annotation for v1 does not match type of assignment [annotation-type-mismatch]
9-
File "specialtypes_never.py", line 68, in func6: Type annotation for v2 does not match type of assignment [annotation-type-mismatch]
10-
File "specialtypes_never.py", line 69, in func6: Type annotation for v3 does not match type of assignment [annotation-type-mismatch]
11-
File "specialtypes_never.py", line 85, in func8: Type annotation for v3 does not match type of assignment [annotation-type-mismatch]
8+
File "specialtypes_never.py", line 64, in func6: Type annotation for v1 does not match type of assignment [annotation-type-mismatch]
9+
File "specialtypes_never.py", line 65, in func6: Type annotation for v2 does not match type of assignment [annotation-type-mismatch]
10+
File "specialtypes_never.py", line 66, in func6: Type annotation for v3 does not match type of assignment [annotation-type-mismatch]
11+
File "specialtypes_never.py", line 82, in func8: Type annotation for v3 does not match type of assignment [annotation-type-mismatch]
1212
"""
1313
conformance_automated = "Fail"
1414
errors_diff = """
1515
Line 19: Expected 1 errors
16-
Line 43: Expected 1 errors
17-
Line 45: Expected 1 errors
18-
Line 50: Expected 1 errors
19-
Line 51: Expected 1 errors
20-
Line 54: Expected 1 errors
21-
Line 59: Expected 1 errors
22-
Line 60: Expected 1 errors
23-
Line 104: Expected 1 errors
16+
Line 101: Expected 1 errors
2417
Line 11: Unexpected errors ['File "specialtypes_never.py", line 11, in <module>: argument "covariant" to TypeVar not supported yet [not-supported-yet]']
2518
Line 21: Unexpected errors ['File "specialtypes_never.py", line 21, in func1: bad return type [bad-return-type]']
26-
Line 67: Unexpected errors ['File "specialtypes_never.py", line 67, in func6: Type annotation for v1 does not match type of assignment [annotation-type-mismatch]']
27-
Line 68: Unexpected errors ['File "specialtypes_never.py", line 68, in func6: Type annotation for v2 does not match type of assignment [annotation-type-mismatch]']
28-
Line 69: Unexpected errors ['File "specialtypes_never.py", line 69, in func6: Type annotation for v3 does not match type of assignment [annotation-type-mismatch]']
19+
Line 64: Unexpected errors ['File "specialtypes_never.py", line 64, in func6: Type annotation for v1 does not match type of assignment [annotation-type-mismatch]']
20+
Line 65: Unexpected errors ['File "specialtypes_never.py", line 65, in func6: Type annotation for v2 does not match type of assignment [annotation-type-mismatch]']
21+
Line 66: Unexpected errors ['File "specialtypes_never.py", line 66, in func6: Type annotation for v3 does not match type of assignment [annotation-type-mismatch]']
2922
"""

conformance/tests/specialtypes_never.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,29 @@ def func2(x: int) -> int:
3232
return "whatever works" # No type error
3333

3434

35-
# The spec says the following, but it is agreed that this is out of date and
36-
# should be changed. No type checkers enforce this currently.
37-
38-
# > The NoReturn type is only valid as a return annotation of functions, and
39-
# > considered an error if it appears in other positions:
35+
# The spec previously said that NoReturn is only valid in a function return type,
36+
# but this was removed and it should now be accepted in all of these contexts:
4037

4138

4239
def func3(
43-
a: NoReturn, b: list[NoReturn] # E: NoReturn used outside of return annotation
40+
a: NoReturn, b: list[NoReturn]
4441
) -> None:
45-
c: NoReturn = a # E: NoReturn used outside of return annotation
42+
c: NoReturn = a
4643

4744

4845
def func4(
4946
a: list[NoReturn],
50-
) -> None: # E: NoReturn used outside of return annotation
51-
c: list[NoReturn] = a # E: NoReturn used outside of return annotation
47+
) -> None:
48+
c: list[NoReturn] = a
5249

5350

54-
def func5() -> list[NoReturn]: # E: NoReturn used outside of return annotation
51+
def func5() -> list[NoReturn]:
5552
return []
5653

5754

5855
class ClassA:
59-
x: NoReturn # E: NoReturn used outside of return annotation
60-
y: list[NoReturn] # E: NoReturn used outside of return annotation
56+
x: NoReturn
57+
y: list[NoReturn]
6158

6259

6360
# Never is compatible with all types.

0 commit comments

Comments
 (0)