Skip to content

Commit

Permalink
Fixed a bug in the conformance tests for TypeVarTuples and removed a … (
Browse files Browse the repository at this point in the history
#1593)

Fixed a bug in the conformance tests for TypeVarTuples and removed a note that I had left in previously. This section in the spec is unfortunately worded and can be interpreted in different ways, but I think I now understood what the PEP authors meant. This change to the tests doesn't change any of the scoring for the four type checkers. Conformance with this part of the spec will require fixes in both pyright and mypy.
  • Loading branch information
erictraut authored Jan 19, 2024
1 parent 1b141ff commit ebb1a42
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion conformance/results/mypy/generics_typevartuple_basic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ generics_typevartuple_basic.py:59: error: TypeVarTuple "Shape" is only valid wit
generics_typevartuple_basic.py:65: error: Unexpected keyword argument "covariant" for "TypeVarTuple" [misc]
generics_typevartuple_basic.py:66: error: Too many positional arguments for "TypeVarTuple" [misc]
generics_typevartuple_basic.py:67: error: Unexpected keyword argument "bound" for "TypeVarTuple" [misc]
generics_typevartuple_basic.py:108: error: Can only use one type var tuple in a class def [misc]
generics_typevartuple_basic.py:106: error: Can only use one type var tuple in a class def [misc]
"""
22 changes: 11 additions & 11 deletions conformance/results/pyre/generics_typevartuple_basic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ generics_typevartuple_basic.py:67:6 Unexpected keyword [28]: Unexpected keyword
generics_typevartuple_basic.py:75:16 Invalid type [31]: Expression `tuple[(*$local_generics_typevartuple_basic$Ts)]` is not a valid type.
generics_typevartuple_basic.py:75:34 Invalid type [31]: Expression `tuple[(*$local_generics_typevartuple_basic$Ts)]` is not a valid type.
generics_typevartuple_basic.py:75:49 Invalid type [31]: Expression `tuple[(*$local_generics_typevartuple_basic$Ts)]` is not a valid type.
generics_typevartuple_basic.py:92:6 Incompatible parameter type [6]: In call `func2`, for 1st positional argument, expected `Tuple[]` but got `Tuple[int, int]`. Expected has length 1, but actual has length 2.
generics_typevartuple_basic.py:95:16 Invalid type [31]: Expression `Array[(*$local_generics_typevartuple_basic$Shape)]` is not a valid type.
generics_typevartuple_basic.py:95:16 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_basic.py:95:34 Invalid type [31]: Expression `Array[(*$local_generics_typevartuple_basic$Shape)]` is not a valid type.
generics_typevartuple_basic.py:95:34 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_basic.py:95:52 Invalid type [31]: Expression `Array[(*$local_generics_typevartuple_basic$Shape)]` is not a valid type.
generics_typevartuple_basic.py:95:52 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_basic.py:99:13 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_basic.py:99:31 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_basic.py:99:48 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_basic.py:108:13 Invalid type [31]: Expression `typing.Generic[(*$local_generics_typevartuple_basic$Ts1, *$local_generics_typevartuple_basic$Ts2)]` is not a valid type.
generics_typevartuple_basic.py:90:6 Incompatible parameter type [6]: In call `func2`, for 1st positional argument, expected `Tuple[]` but got `Tuple[int, int]`. Expected has length 1, but actual has length 2.
generics_typevartuple_basic.py:93:16 Invalid type [31]: Expression `Array[(*$local_generics_typevartuple_basic$Shape)]` is not a valid type.
generics_typevartuple_basic.py:93:16 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_basic.py:93:34 Invalid type [31]: Expression `Array[(*$local_generics_typevartuple_basic$Shape)]` is not a valid type.
generics_typevartuple_basic.py:93:34 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_basic.py:93:52 Invalid type [31]: Expression `Array[(*$local_generics_typevartuple_basic$Shape)]` is not a valid type.
generics_typevartuple_basic.py:93:52 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_basic.py:97:13 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_basic.py:97:31 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_basic.py:97:48 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_basic.py:106:13 Invalid type [31]: Expression `typing.Generic[(*$local_generics_typevartuple_basic$Ts1, *$local_generics_typevartuple_basic$Ts2)]` is not a valid type.
"""
12 changes: 6 additions & 6 deletions conformance/results/pyright/generics_typevartuple_basic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ generics_typevartuple_basic.py:65:27 - error: "covariant" is unknown parameter t
generics_typevartuple_basic.py:66:27 - error: TypeVarTuple cannot have value constraints
generics_typevartuple_basic.py:66:32 - error: TypeVarTuple cannot have value constraints
generics_typevartuple_basic.py:67:27 - error: "bound" is unknown parameter to TypeVarTuple
generics_typevartuple_basic.py:92:15 - error: Argument of type "tuple[Literal[0]]" cannot be assigned to parameter "arg2" of type "tuple[*Ts@func2]" in function "func2"
generics_typevartuple_basic.py:90:15 - error: Argument of type "tuple[Literal[0]]" cannot be assigned to parameter "arg2" of type "tuple[*Ts@func2]" in function "func2"
  "tuple[Literal[0]]" is incompatible with "tuple[int, int]"
    Tuple size mismatch; expected 2 but received 1 (reportGeneralTypeIssues)
generics_typevartuple_basic.py:101:14 - error: Argument of type "Array[Height]" cannot be assigned to parameter "x" of type "Array[*Shape@multiply]" in function "multiply"
generics_typevartuple_basic.py:99:14 - error: Argument of type "Array[Height]" cannot be assigned to parameter "x" of type "Array[*Shape@multiply]" in function "multiply"
  "Array[Height]" is incompatible with "Array[Height | Width]"
    Type parameter "Shape@Array" is invariant, but "*tuple[Height]" is not the same as "*tuple[Height | Width]" (reportGeneralTypeIssues)
generics_typevartuple_basic.py:101:17 - error: Argument of type "Array[Width]" cannot be assigned to parameter "y" of type "Array[*Shape@multiply]" in function "multiply"
generics_typevartuple_basic.py:99:17 - error: Argument of type "Array[Width]" cannot be assigned to parameter "y" of type "Array[*Shape@multiply]" in function "multiply"
  "Array[Width]" is incompatible with "Array[Height | Width]"
    Type parameter "Shape@Array" is invariant, but "*tuple[Width]" is not the same as "*tuple[Height | Width]" (reportGeneralTypeIssues)
generics_typevartuple_basic.py:102:17 - error: Argument of type "Array[Height, Width]" cannot be assigned to parameter "y" of type "Array[*Shape@multiply]" in function "multiply"
generics_typevartuple_basic.py:100:17 - error: Argument of type "Array[Height, Width]" cannot be assigned to parameter "y" of type "Array[*Shape@multiply]" in function "multiply"
  "Array[Height, Width]" is incompatible with "Array[Height]"
    Type parameter "Shape@Array" is invariant, but "*tuple[Height, Width]" is not the same as "*tuple[Height]" (reportGeneralTypeIssues)
generics_typevartuple_basic.py:108:14 - error: Generic class can have at most one TypeVarTuple type parameter but received multiple ("Ts1", "Ts2")
generics_typevartuple_basic.py:108:29 - error: Type argument list can have at most one unpacked TypeVarTuple or Tuple
generics_typevartuple_basic.py:106:14 - error: Generic class can have at most one TypeVarTuple type parameter but received multiple ("Ts1", "Ts2")
generics_typevartuple_basic.py:106:29 - error: Type argument list can have at most one unpacked TypeVarTuple or Tuple
"""
16 changes: 8 additions & 8 deletions conformance/results/pytype/generics_typevartuple_basic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,24 @@ File "generics_typevartuple_basic.py", line 76, in func2: bad return type [bad-r
Expected: Tuple[Any]
Actually returned: None
Called from (traceback):
line 87, in current file
File "generics_typevartuple_basic.py", line 87, in <module>: Tuple[Any] [assert-type]
line 84, in current file
File "generics_typevartuple_basic.py", line 84, in <module>: Tuple[Any] [assert-type]
Expected: Tuple[int]
Actual: Tuple[Any]
File "generics_typevartuple_basic.py", line 92, in <module>: Function func2 was called with the wrong arguments [wrong-arg-types]
File "generics_typevartuple_basic.py", line 90, in <module>: Function func2 was called with the wrong arguments [wrong-arg-types]
Expected: (arg1: Tuple[Any], ...)
Actually passed: (arg1: Tuple[int, int], ...)
File "generics_typevartuple_basic.py", line 95, in <module>: class Array is not indexable [not-indexable]
File "generics_typevartuple_basic.py", line 93, in <module>: class Array is not indexable [not-indexable]
('Array' does not subclass Generic)
File "generics_typevartuple_basic.py", line 96, in multiply: bad return type [bad-return-type]
File "generics_typevartuple_basic.py", line 94, in multiply: bad return type [bad-return-type]
Expected: Array
Actually returned: None
File "generics_typevartuple_basic.py", line 99, in <module>: class Array is not indexable [not-indexable]
File "generics_typevartuple_basic.py", line 97, in <module>: class Array is not indexable [not-indexable]
('Array' does not subclass Generic)
File "generics_typevartuple_basic.py", line 108, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]
File "generics_typevartuple_basic.py", line 106, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]
Expected: (self, i: Iterable)
Actually passed: (self, i: TypeVarTuple)
Attributes of protocol Iterable[_T2] are not implemented on TypeVarTuple: __iter__
File "generics_typevartuple_basic.py", line 108, in <module>: Invalid type annotation 'Generic' [invalid-annotation]
File "generics_typevartuple_basic.py", line 106, in <module>: Invalid type annotation 'Generic' [invalid-annotation]
Parameters to Generic[...] must all be type variables
"""
2 changes: 1 addition & 1 deletion conformance/results/results.html

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions conformance/tests/generics_typevartuple_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ def func2(arg1: tuple[*Ts], arg2: tuple[*Ts]) -> tuple[*Ts]:
# > the types must match exactly (the list of type parameters must be the
# > same length, and the type parameters themselves must be identical)

# Note from Eric Traut: The above provision in the spec is very problematic
# and will likely need to be changed.

assert_type(func2((0,), (1,)), tuple[int]) # OK
func2((0,), ("0",)) # Type error?
func2((0,), (0.0,)) # Type error?
func2((0.0,), (0,)) # Type error?
func2((0,), (1,)) # Type error?
func2((0,), (0.0,)) # OK
func2((0.0,), (0,)) # OK
func2((0,), (1,)) # OK

func2((0,), ("0",)) # Type error
func2((0, 0), (0,)) # Type error


Expand Down

0 comments on commit ebb1a42

Please sign in to comment.