Skip to content

Commit 92287d4

Browse files
committed
specify that type variable tuples and parameter specification should have variance
1 parent 2b960aa commit 92287d4

39 files changed

Lines changed: 1119 additions & 136 deletions
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
conformant = "Pass"
2+
conformance_automated = "Pass"
3+
errors_diff = """
4+
"""
5+
output = """
6+
generics_mixed_variance_inference.py:13: error: Incompatible types in assignment (expression has type "Mixed[bool, []]", variable has type "Mixed[int, []]") [assignment]
7+
generics_mixed_variance_inference.py:16: error: Incompatible types in assignment (expression has type "Mixed[int, object, []]", variable has type "Mixed[int, int, []]") [assignment]
8+
generics_mixed_variance_inference.py:21: error: Incompatible types in assignment (expression has type "Mixed[int, [bool]]", variable has type "Mixed[int, [int]]") [assignment]
9+
"""
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
conformant = "Unsupported"
2+
conformance_automated = "Fail"
3+
errors_diff = """
4+
Line 15: Expected 1 errors
5+
Line 30: Expected 1 errors
6+
Line 64: Expected 1 errors
7+
Line 110: Expected 1 errors
8+
Line 121: Expected 1 errors
9+
Line 127: Expected 1 errors
10+
Line 31: Unexpected errors ['generics_paramspec_variance.py:31: error: Incompatible types in assignment (expression has type "CovariantParamSpec[[int]]", variable has type "CovariantParamSpec[[object]]") [assignment]']
11+
Line 58: Unexpected errors ['generics_paramspec_variance.py:58: error: Incompatible types in assignment (expression has type "InitP[[NamedArg(int, \\'a\\')]]", variable has type "InitP[[int]]") [assignment]']
12+
Line 60: Unexpected errors ['generics_paramspec_variance.py:60: error: Incompatible types in assignment (expression has type "InitP[[int]]", variable has type "InitP[[Arg(int, \\'a\\')]]") [assignment]']
13+
Line 76: Unexpected errors ['generics_paramspec_variance.py:76: error: Argument 1 to "Box" has incompatible type "OutitP[[int]]"; expected "InitP[[int]]" [arg-type]']
14+
Line 78: Unexpected errors ['generics_paramspec_variance.py:78: error: Incompatible types in assignment (expression has type "OutitP[[NamedArg(int, \\'a\\')]]", variable has type "InitP[[NamedArg(int, \\'a\\')]]") [assignment]']
15+
Line 80: Unexpected errors ['generics_paramspec_variance.py:80: error: Incompatible types in assignment (expression has type "OutitP[[int]]", variable has type "InitP[[int]]") [assignment]']
16+
Line 82: Unexpected errors ['generics_paramspec_variance.py:82: error: Incompatible types in assignment (expression has type "OutitP[[int]]", variable has type "InitP[[int]]") [assignment]']
17+
Line 83: Unexpected errors ['generics_paramspec_variance.py:83: error: Name "_" already defined on line 62 [no-redef]', 'generics_paramspec_variance.py:83: error: Invalid type comment or annotation [valid-type]']
18+
Line 84: Unexpected errors ['generics_paramspec_variance.py:84: error: Incompatible types in assignment (expression has type "OutitP[[int]]", variable has type "InitP[[int]]") [assignment]']
19+
Line 86: Unexpected errors ['generics_paramspec_variance.py:86: error: Incompatible types in assignment (expression has type "OutitP[[int, str]]", variable has type "InitP[[int, str]]") [assignment]']
20+
Line 91: Unexpected errors ['generics_paramspec_variance.py:91: error: String argument 1 "InP" to ParamSpec(...) does not match variable name "P" [misc]']
21+
Line 92: Unexpected errors ['generics_paramspec_variance.py:92: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]']
22+
Line 97: Unexpected errors ['generics_paramspec_variance.py:97: error: Free type variable expected in Generic[...] [misc]']
23+
Line 101: Unexpected errors ['generics_paramspec_variance.py:101: error: "InvariantParamSpecOld" expects no type arguments, but 1 given [type-arg]']
24+
Line 102: Unexpected errors ['generics_paramspec_variance.py:102: error: The type "type[InvariantParamSpecOld]" is not generic and not indexable [misc]']
25+
Line 117: Unexpected errors ['generics_paramspec_variance.py:117: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]']
26+
Line 128: Unexpected errors ['generics_paramspec_variance.py:128: error: Incompatible types in assignment (expression has type "CovariantParamSpecOld[[int]]", variable has type "CovariantParamSpecOld[[object]]") [assignment]']
27+
"""
28+
output = """
29+
generics_paramspec_variance.py:14: error: Incompatible types in assignment (expression has type "InvariantParamSpec[[int]]", variable has type "InvariantParamSpec[[object]]") [assignment]
30+
generics_paramspec_variance.py:21: error: Incompatible types in assignment (expression has type "ContravariantParamSpec[[int]]", variable has type "ContravariantParamSpec[[object]]") [assignment]
31+
generics_paramspec_variance.py:31: error: Incompatible types in assignment (expression has type "CovariantParamSpec[[int]]", variable has type "CovariantParamSpec[[object]]") [assignment]
32+
generics_paramspec_variance.py:58: error: Incompatible types in assignment (expression has type "InitP[[NamedArg(int, 'a')]]", variable has type "InitP[[int]]") [assignment]
33+
generics_paramspec_variance.py:60: error: Incompatible types in assignment (expression has type "InitP[[int]]", variable has type "InitP[[Arg(int, 'a')]]") [assignment]
34+
generics_paramspec_variance.py:62: error: Invalid type comment or annotation [valid-type]
35+
generics_paramspec_variance.py:66: error: Incompatible types in assignment (expression has type "InitP[[int, str]]", variable has type "InitP[[int]]") [assignment]
36+
generics_paramspec_variance.py:76: error: Argument 1 to "Box" has incompatible type "OutitP[[int]]"; expected "InitP[[int]]" [arg-type]
37+
generics_paramspec_variance.py:78: error: Incompatible types in assignment (expression has type "OutitP[[NamedArg(int, 'a')]]", variable has type "InitP[[NamedArg(int, 'a')]]") [assignment]
38+
generics_paramspec_variance.py:79: error: Incompatible types in assignment (expression has type "InitP[[NamedArg(int, 'a')]]", variable has type "InitP[[int]]") [assignment]
39+
generics_paramspec_variance.py:80: error: Incompatible types in assignment (expression has type "OutitP[[int]]", variable has type "InitP[[int]]") [assignment]
40+
generics_paramspec_variance.py:81: error: Incompatible types in assignment (expression has type "InitP[[int]]", variable has type "InitP[[Arg(int, 'a')]]") [assignment]
41+
generics_paramspec_variance.py:82: error: Incompatible types in assignment (expression has type "OutitP[[int]]", variable has type "InitP[[int]]") [assignment]
42+
generics_paramspec_variance.py:83: error: Name "_" already defined on line 62 [no-redef]
43+
generics_paramspec_variance.py:83: error: Invalid type comment or annotation [valid-type]
44+
generics_paramspec_variance.py:84: error: Incompatible types in assignment (expression has type "OutitP[[int]]", variable has type "InitP[[int]]") [assignment]
45+
generics_paramspec_variance.py:86: error: Incompatible types in assignment (expression has type "OutitP[[int, str]]", variable has type "InitP[[int, str]]") [assignment]
46+
generics_paramspec_variance.py:87: error: Incompatible types in assignment (expression has type "InitP[[int, str]]", variable has type "InitP[[int]]") [assignment]
47+
generics_paramspec_variance.py:91: error: String argument 1 "InP" to ParamSpec(...) does not match variable name "P" [misc]
48+
generics_paramspec_variance.py:92: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]
49+
generics_paramspec_variance.py:93: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]
50+
generics_paramspec_variance.py:94: error: String argument 1 "InvP1" to ParamSpec(...) does not match variable name "InvP2" [misc]
51+
generics_paramspec_variance.py:95: error: String argument 1 "InvP1" to ParamSpec(...) does not match variable name "InvP3" [misc]
52+
generics_paramspec_variance.py:97: error: Free type variable expected in Generic[...] [misc]
53+
generics_paramspec_variance.py:101: error: "InvariantParamSpecOld" expects no type arguments, but 1 given [type-arg]
54+
generics_paramspec_variance.py:102: error: The type "type[InvariantParamSpecOld]" is not generic and not indexable [misc]
55+
generics_paramspec_variance.py:103: error: The type "type[InvariantParamSpecOld]" is not generic and not indexable [misc]
56+
generics_paramspec_variance.py:104: error: The type "type[InvariantParamSpecOld]" is not generic and not indexable [misc]
57+
generics_paramspec_variance.py:114: error: Incompatible types in assignment (expression has type "ContravariantParamSpecOld[[int]]", variable has type "ContravariantParamSpecOld[[object]]") [assignment]
58+
generics_paramspec_variance.py:117: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]
59+
generics_paramspec_variance.py:128: error: Incompatible types in assignment (expression has type "CovariantParamSpecOld[[int]]", variable has type "CovariantParamSpecOld[[object]]") [assignment]
60+
"""

conformance/results/mypy/generics_typevartuple_basic.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ notes = """
33
Does not enforce that tuples captured by `TypeVarTuple` are same length.
44
"""
55
output = """
6-
generics_typevartuple_basic.py:42: error: Argument 1 to "Array" has incompatible type "Height"; expected "tuple[Height, Width]" [arg-type]
7-
generics_typevartuple_basic.py:43: error: Argument 1 to "Array" has incompatible type "tuple[Batch, Width]"; expected "tuple[Batch, Height, Width]" [arg-type]
8-
generics_typevartuple_basic.py:45: error: Argument 1 to "Array" has incompatible type "tuple[Time, Batch, Width, Height]"; expected "tuple[Time, Batch, Height, Width]" [arg-type]
9-
generics_typevartuple_basic.py:52: error: Free type variable expected in Generic[...] [misc]
10-
generics_typevartuple_basic.py:53: error: TypeVarTuple "Shape" is only valid with an unpack [valid-type]
11-
generics_typevartuple_basic.py:56: error: TypeVarTuple "Shape" is only valid with an unpack [valid-type]
12-
generics_typevartuple_basic.py:59: error: TypeVarTuple "Shape" is only valid with an unpack [valid-type]
13-
generics_typevartuple_basic.py:65: error: Unexpected keyword argument "covariant" for "TypeVarTuple" [misc]
6+
generics_typevartuple_basic.py:43: error: Argument 1 to "Array" has incompatible type "Height"; expected "tuple[Height, Width]" [arg-type]
7+
generics_typevartuple_basic.py:44: error: Argument 1 to "Array" has incompatible type "tuple[Batch, Width]"; expected "tuple[Batch, Height, Width]" [arg-type]
8+
generics_typevartuple_basic.py:46: error: Argument 1 to "Array" has incompatible type "tuple[Time, Batch, Width, Height]"; expected "tuple[Time, Batch, Height, Width]" [arg-type]
9+
generics_typevartuple_basic.py:53: error: Free type variable expected in Generic[...] [misc]
10+
generics_typevartuple_basic.py:54: error: TypeVarTuple "Shape" is only valid with an unpack [valid-type]
11+
generics_typevartuple_basic.py:57: error: TypeVarTuple "Shape" is only valid with an unpack [valid-type]
12+
generics_typevartuple_basic.py:60: error: TypeVarTuple "Shape" is only valid with an unpack [valid-type]
1413
generics_typevartuple_basic.py:66: error: Too many positional arguments for "TypeVarTuple" [misc]
1514
generics_typevartuple_basic.py:67: error: Unexpected keyword argument "bound" for "TypeVarTuple" [misc]
1615
generics_typevartuple_basic.py:100: error: Cannot infer value of type parameter "Shape" of "multiply" [misc]
1716
generics_typevartuple_basic.py:101: error: Cannot infer value of type parameter "Shape" of "multiply" [misc]
1817
generics_typevartuple_basic.py:107: error: Can only use one type var tuple in a class def [misc]
18+
generics_typevartuple_basic.py:111: error: Can only use one type var tuple in a class def [misc]
1919
"""
2020
conformance_automated = "Fail"
2121
errors_diff = """
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
conformant = "Unsupported"
2+
conformance_automated = "Fail"
3+
errors_diff = """
4+
Line 14: Expected 1 errors
5+
Line 18: Expected 1 errors
6+
Line 26: Expected 1 errors
7+
Line 29: Expected 1 errors
8+
Line 61: Expected 1 errors
9+
Line 72: Expected 1 errors
10+
Line 76: Expected 1 errors
11+
Line 83: Expected 1 errors
12+
Line 27: Unexpected errors ['generics_typevartuple_variance.py:27: error: Incompatible types in assignment (expression has type "ContravariantTypeVarTuple[object]", variable has type "ContravariantTypeVarTuple[int]") [assignment]']
13+
Line 28: Unexpected errors ['generics_typevartuple_variance.py:28: error: Incompatible types in assignment (expression has type "ContravariantTypeVarTuple[*tuple[object, ...]]", variable has type "ContravariantTypeVarTuple[*tuple[int, ...]]") [assignment]']
14+
Line 66: Unexpected errors ['generics_typevartuple_variance.py:66: error: Unexpected keyword argument "contravariant" for "TypeVarTuple" [misc]']
15+
Line 77: Unexpected errors ['generics_typevartuple_variance.py:77: error: Incompatible types in assignment (expression has type "ContravariantTypeVarTupleOld[object]", variable has type "ContravariantTypeVarTupleOld[int]") [assignment]']
16+
Line 80: Unexpected errors ['generics_typevartuple_variance.py:80: error: Unexpected keyword argument "covariant" for "TypeVarTuple" [misc]']
17+
"""
18+
output = """
19+
generics_typevartuple_variance.py:15: error: Incompatible types in assignment (expression has type "InvariantTypeVarTuple[object]", variable has type "InvariantTypeVarTuple[int]") [assignment]
20+
generics_typevartuple_variance.py:17: error: Incompatible types in assignment (expression has type "InvariantTypeVarTuple[*tuple[object, ...]]", variable has type "InvariantTypeVarTuple[*tuple[int, ...]]") [assignment]
21+
generics_typevartuple_variance.py:27: error: Incompatible types in assignment (expression has type "ContravariantTypeVarTuple[object]", variable has type "ContravariantTypeVarTuple[int]") [assignment]
22+
generics_typevartuple_variance.py:28: error: Incompatible types in assignment (expression has type "ContravariantTypeVarTuple[*tuple[object, ...]]", variable has type "ContravariantTypeVarTuple[*tuple[int, ...]]") [assignment]
23+
generics_typevartuple_variance.py:38: error: Incompatible types in assignment (expression has type "CovariantTypeVarTuple[object]", variable has type "CovariantTypeVarTuple[int]") [assignment]
24+
generics_typevartuple_variance.py:41: error: Incompatible types in assignment (expression has type "CovariantTypeVarTuple[bool, object]", variable has type "CovariantTypeVarTuple[int, int]") [assignment]
25+
generics_typevartuple_variance.py:42: error: Incompatible types in assignment (expression has type "CovariantTypeVarTuple[object, bool]", variable has type "CovariantTypeVarTuple[int, int]") [assignment]
26+
generics_typevartuple_variance.py:43: error: Incompatible types in assignment (expression has type "CovariantTypeVarTuple[object, object]", variable has type "CovariantTypeVarTuple[int, int]") [assignment]
27+
generics_typevartuple_variance.py:44: error: Incompatible types in assignment (expression has type "CovariantTypeVarTuple[*tuple[object, ...]]", variable has type "CovariantTypeVarTuple[*tuple[int, ...]]") [assignment]
28+
generics_typevartuple_variance.py:49: error: Unexpected keyword argument "covariant" for "TypeVarTuple" [misc]
29+
generics_typevartuple_variance.py:49: error: Unexpected keyword argument "contravariant" for "TypeVarTuple" [misc]
30+
generics_typevartuple_variance.py:50: error: Unexpected keyword argument "covariant" for "TypeVarTuple" [misc]
31+
generics_typevartuple_variance.py:50: error: Unexpected keyword argument "infer_variance" for "TypeVarTuple" [misc]
32+
generics_typevartuple_variance.py:51: error: Unexpected keyword argument "covariant" for "TypeVarTuple" [misc]
33+
generics_typevartuple_variance.py:51: error: Unexpected keyword argument "infer_variance" for "TypeVarTuple" [misc]
34+
generics_typevartuple_variance.py:62: error: Incompatible types in assignment (expression has type "InvariantTypeVarTupleOld[object]", variable has type "InvariantTypeVarTupleOld[int]") [assignment]
35+
generics_typevartuple_variance.py:66: error: Unexpected keyword argument "contravariant" for "TypeVarTuple" [misc]
36+
generics_typevartuple_variance.py:77: error: Incompatible types in assignment (expression has type "ContravariantTypeVarTupleOld[object]", variable has type "ContravariantTypeVarTupleOld[int]") [assignment]
37+
generics_typevartuple_variance.py:80: error: Unexpected keyword argument "covariant" for "TypeVarTuple" [misc]
38+
generics_typevartuple_variance.py:90: error: Incompatible types in assignment (expression has type "CovariantTypeVarTupleOld[object]", variable has type "CovariantTypeVarTupleOld[int]") [assignment]
39+
"""
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
False report of ParamSpec variance keywords.
4+
"""
25
output = """
3-
protocols_variance.py:21: error: Invariant type variable "T1" used in protocol where covariant one is expected [misc]
4-
protocols_variance.py:40: error: Invariant type variable "T3" used in protocol where contravariant one is expected [misc]
5-
protocols_variance.py:56: error: Invariant type variable "T1" used in protocol where contravariant one is expected [misc]
6-
protocols_variance.py:61: error: Covariant type variable "T1_co" used in protocol where contravariant one is expected [misc]
7-
protocols_variance.py:62: error: Cannot use a covariant type variable as a parameter [misc]
8-
protocols_variance.py:66: error: Invariant type variable "T1" used in protocol where covariant one is expected [misc]
9-
protocols_variance.py:71: error: Contravariant type variable "T1_contra" used in protocol where covariant one is expected [misc]
10-
protocols_variance.py:72: error: Cannot use a contravariant type variable as return type [misc]
11-
protocols_variance.py:104: error: Invariant type variable "T1" used in protocol where covariant one is expected [misc]
6+
protocols_variance.py:15: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]
7+
protocols_variance.py:22: error: Invariant type variable "T1" used in protocol where covariant one is expected [misc]
8+
protocols_variance.py:41: error: Invariant type variable "T3" used in protocol where contravariant one is expected [misc]
9+
protocols_variance.py:57: error: Invariant type variable "T1" used in protocol where contravariant one is expected [misc]
10+
protocols_variance.py:62: error: Covariant type variable "T1_co" used in protocol where contravariant one is expected [misc]
11+
protocols_variance.py:63: error: Cannot use a covariant type variable as a parameter [misc]
12+
protocols_variance.py:67: error: Invariant type variable "T1" used in protocol where covariant one is expected [misc]
13+
protocols_variance.py:72: error: Contravariant type variable "T1_contra" used in protocol where covariant one is expected [misc]
14+
protocols_variance.py:73: error: Cannot use a contravariant type variable as return type [misc]
15+
protocols_variance.py:105: error: Invariant type variable "T1" used in protocol where covariant one is expected [misc]
1216
"""
13-
conformance_automated = "Pass"
17+
conformance_automated = "Fail"
1418
errors_diff = """
19+
Line 15: Unexpected errors ['protocols_variance.py:15: error: The variance and bound arguments to ParamSpec do not have defined semantics yet [misc]']
1520
"""

0 commit comments

Comments
 (0)