Skip to content

Commit

Permalink
Fixed a few bugs in the conformance tests: (#1585)
Browse files Browse the repository at this point in the history
* Updated comments in `protocols_explicit` to clarify that error must be generated at class instantiation time rather than class declaration time. Updated pyright results to indicate that it does not pass this test.
* Fixed a couple of bugs in the `generics_typevartuple_specialization` test that caused the test not to properly test what it was intended to test.
* Added a missing test to the `generics_typevartuple_callable` test.
* Fixed a bug in the `generics_typevartuple_basic` test that caused the test not to properly test what was intended.
  • Loading branch information
erictraut committed Jan 15, 2024
1 parent 4b7d0b7 commit c077170
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 75 deletions.
3 changes: 1 addition & 2 deletions conformance/results/mypy/generics_typevartuple_basic.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
conformant = "Partial"
notes = """
Does not enforce that tuples captured by TypeVarTuple are same length (spec bug?).
Does not enforce that tuples captured by TypeVarTuple are same length.
Does not enforce that tuples captured by TypeVarTuple are same type (spec bug?).
Does not enforce that tuples captured by TypeVarTuple are invariant in non-tuple class.
"""
Expand All @@ -16,6 +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:87: error: Expression is of type "tuple[tuple[int], tuple[int]]", not "tuple[int]" [assert-type]
generics_typevartuple_basic.py:108: error: Can only use one type var tuple in a class def [misc]
"""
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
conformant = "Partial"
notes = """
Incorrectly reports type incompatibility when generic class is specialized with `*tuple[Any, ...]`.
Incorrectly specializes generic alias that includes a TypeVar and TypeVarTuple if no type arguments are provided.
Rejects use of unpacked TypeVarTuple in generic type alias definition.
Rejects specialization of generic type alias defined as a tuple containing a TypeVar.
"More than one Unpack" error message has no line number.
Incorrectly evaluates tuple split across a TypeVarTuple and a TypeVar.
"""
output = """
generics_typevartuple_specialization.py: error: More than one Unpack in a type is not allowed [misc]
generics_typevartuple_specialization.py:85: error: Argument 1 to "takes_float_array_with_specific_shape" has incompatible type "Array2[float, *tuple[Any, ...]]"; expected "Array2[float, Height, Width]" [arg-type]
generics_typevartuple_specialization.py:95: error: Expression is of type "tuple[Any, *tuple[Any, ...]]", not "tuple[Any, ...]" [assert-type]
generics_typevartuple_specialization.py:108: error: Type application is only supported for generic classes [misc]
generics_typevartuple_specialization.py:109: error: Type application is only supported for generic classes [misc]
generics_typevartuple_specialization.py:109: error: Unpack is only valid in a variadic position [valid-type]
generics_typevartuple_specialization.py:110: error: Type application is only supported for generic classes [misc]
generics_typevartuple_specialization.py:110: error: Unpack is only valid in a variadic position [valid-type]
generics_typevartuple_specialization.py:127: error: Bad number of arguments for type alias, expected: at least 2, given: 1 [type-arg]
generics_typevartuple_specialization.py:159: error: Expression is of type "tuple[str, *tuple[int, ...]]", not "tuple[str, *tuple[int, ...], int]" [assert-type]
generics_typevartuple_specialization.py:163: error: TypeVarTuple "Ts2" is unbound [valid-type]
generics_typevartuple_specialization.py:163: error: TypeVarTuple cannot be split [type-arg]
"""
8 changes: 4 additions & 4 deletions conformance/results/mypy/protocols_explicit.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ output = """
protocols_explicit.py:27: error: Call to abstract method "draw" of "PColor" with trivial body via super() is unsafe [safe-super]
protocols_explicit.py:56: error: Incompatible types in assignment (expression has type "tuple[int, int, str]", base class "RGB" defined the type as "tuple[int, int, int]") [assignment]
protocols_explicit.py:63: error: Cannot instantiate abstract class "Point" with abstract attributes "intensity", "other" and "transparency" [abstract]
protocols_explicit.py:92: error: Cannot instantiate abstract class "Concrete1" with abstract attributes "cm1" and "im1" [abstract]
protocols_explicit.py:114: error: Cannot instantiate abstract class "Concrete3" with abstract attributes "cm10", "cm11" and "im1" [abstract]
protocols_explicit.py:140: error: Cannot instantiate abstract class "Concrete5" with abstract attribute "method1" [abstract]
protocols_explicit.py:171: error: Cannot instantiate abstract class "Concrete7A" with abstract attribute "method1" [abstract]
protocols_explicit.py:90: error: Cannot instantiate abstract class "Concrete1" with abstract attributes "cm1" and "im1" [abstract]
protocols_explicit.py:108: error: Cannot instantiate abstract class "Concrete3" with abstract attributes "cm10", "cm11" and "im1" [abstract]
protocols_explicit.py:133: error: Cannot instantiate abstract class "Concrete5" with abstract attribute "method1" [abstract]
protocols_explicit.py:163: error: Cannot instantiate abstract class "Concrete7A" with abstract attribute "method1" [abstract]
"""
1 change: 1 addition & 0 deletions conformance/results/pyre/generics_typevartuple_basic.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ generics_typevartuple_callable.py:42:18 Incompatible parameter type [6]: In call
generics_typevartuple_callable.py:45:17 Invalid type [31]: Expression `*tuple[(int, *$local_generics_typevartuple_callable$Ts, $local_generics_typevartuple_callable$T)]` is not a valid type.
generics_typevartuple_callable.py:45:42 Invalid type [31]: Expression `tuple[($local_generics_typevartuple_callable$T, *$local_generics_typevartuple_callable$Ts)]` is not a valid type.
generics_typevartuple_callable.py:45:42 Invalid type variable [34]: The type variable `Variable[T]` isn't present in the function's parameters.
generics_typevartuple_callable.py:49:41 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[float], Type[str], Type[complex]]`.
"""
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ generics_typevartuple_specialization.py:72:38 Undefined or invalid type [11]: An
generics_typevartuple_specialization.py:89:22 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `typing.Tuple[TypeVar, *Tuple[typing.Any, ...]]`.
generics_typevartuple_specialization.py:92:13 Undefined or invalid type [11]: Annotation `VariadicTuple` is not defined as a type.
generics_typevartuple_specialization.py:93:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[str], Type[int]]`.
generics_typevartuple_specialization.py:95:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[object, typing.Any]`.
generics_typevartuple_specialization.py:95:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `typing.Tuple[object, *Tuple[typing.Any, ...]]`.
generics_typevartuple_specialization.py:95:25 Unable to concatenate tuple [60]: Expected to unpack an iterable, but got `typing.Type[tuple[Variable[_T_co](covariant)]]`.
generics_typevartuple_specialization.py:95:37 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[object, typing.Any]`.
generics_typevartuple_specialization.py:101:20 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `typing.Tuple[Type[int], *Tuple[typing.Any, ...]]`.
generics_typevartuple_specialization.py:103:32 Unable to concatenate tuple [60]: Expected to unpack an iterable, but got `typing.Type[tuple[Variable[_T_co](covariant)]]`.
generics_typevartuple_specialization.py:103:39 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[float], typing.Any]`.
Expand Down Expand Up @@ -77,17 +79,15 @@ generics_typevartuple_specialization.py:153:18 Incompatible parameter type [6]:
generics_typevartuple_specialization.py:156:14 Undefined or invalid type [11]: Annotation `TA10` is not defined as a type.
generics_typevartuple_specialization.py:156:23 Invalid type [31]: Expression `$local_generics_typevartuple_specialization$TA9[(*tuple[(int, ...)], str)]` is not a valid type.
generics_typevartuple_specialization.py:156:23 Undefined or invalid type [11]: Annotation `TA9` is not defined as a type.
generics_typevartuple_specialization.py:156:54 Invalid type [31]: Expression `$local_generics_typevartuple_specialization$TA9[(str, *tuple[(int, ...)])]` is not a valid type.
generics_typevartuple_specialization.py:156:54 Invalid type [31]: Expression `$local_generics_typevartuple_specialization$TA9[(*tuple[(int, ...)], str)]` is not a valid type.
generics_typevartuple_specialization.py:157:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `typing.Tuple[*Tuple[typing.Any, ...], Type[int]]`.
generics_typevartuple_specialization.py:157:25 Unable to concatenate tuple [60]: Expected to unpack an iterable, but got `typing.Type[tuple[Variable[_T_co](covariant)]]`.
generics_typevartuple_specialization.py:157:32 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[int], typing.Any]`.
generics_typevartuple_specialization.py:158:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `typing.Tuple[*Tuple[typing.Any, ...], Type[str]]`.
generics_typevartuple_specialization.py:158:25 Unable to concatenate tuple [60]: Expected to unpack an iterable, but got `typing.Type[tuple[Variable[_T_co](covariant)]]`.
generics_typevartuple_specialization.py:158:32 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[int], typing.Any]`.
generics_typevartuple_specialization.py:159:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `typing.Tuple[Type[str], *Tuple[typing.Any, ...], Type[int]]`.
generics_typevartuple_specialization.py:159:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `typing.Tuple[*Tuple[typing.Any, ...], Type[str]]`.
generics_typevartuple_specialization.py:159:25 Unable to concatenate tuple [60]: Expected to unpack an iterable, but got `typing.Type[tuple[Variable[_T_co](covariant)]]`.
generics_typevartuple_specialization.py:159:37 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[int], typing.Any]`.
generics_typevartuple_specialization.py:159:32 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[int], typing.Any]`.
generics_typevartuple_specialization.py:162:13 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `typing.Tuple[TypeVar, *Tuple[typing.Any, ...]]`.
generics_typevartuple_specialization.py:163:4 Invalid type [31]: Expression `$local_generics_typevartuple_specialization$TA11[(*$local_generics_typevartuple_specialization$Ts2)]` is not a valid type.
generics_typevartuple_specialization.py:163:4 Undefined or invalid type [11]: Annotation `TA11` is not defined as a type.
"""
8 changes: 4 additions & 4 deletions conformance/results/pyre/protocols_explicit.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ protocols_explicit.py:54:0 Uninitialized attribute [13]: Attribute `other` inher
protocols_explicit.py:63:4 Invalid class instantiation [45]: Cannot instantiate abstract class `Point` with abstract method `intensity`.
protocols_explicit.py:86:0 Uninitialized attribute [13]: Attribute `cm1` inherited from protocol `Proto1` in class `Concrete1` to have type `int` but is never initialized.
protocols_explicit.py:86:0 Uninitialized attribute [13]: Attribute `im1` inherited from protocol `Proto1` in class `Concrete1` to have type `int` but is never initialized.
protocols_explicit.py:103:0 Uninitialized attribute [13]: Attribute `cm10` inherited from protocol `Proto2` in class `Concrete3` to have type `int` but is never initialized.
protocols_explicit.py:103:0 Uninitialized attribute [13]: Attribute `cm11` inherited from protocol `Proto3` in class `Concrete3` to have type `int` but is never initialized.
protocols_explicit.py:103:0 Uninitialized attribute [13]: Attribute `im1` inherited from protocol `Proto1` in class `Concrete3` to have type `int` but is never initialized.
protocols_explicit.py:171:6 Invalid class instantiation [45]: Cannot instantiate abstract class `Concrete7A` with abstract method `method1`.
protocols_explicit.py:101:0 Uninitialized attribute [13]: Attribute `cm10` inherited from protocol `Proto2` in class `Concrete3` to have type `int` but is never initialized.
protocols_explicit.py:101:0 Uninitialized attribute [13]: Attribute `cm11` inherited from protocol `Proto3` in class `Concrete3` to have type `int` but is never initialized.
protocols_explicit.py:101:0 Uninitialized attribute [13]: Attribute `im1` inherited from protocol `Proto1` in class `Concrete3` to have type `int` but is never initialized.
protocols_explicit.py:163:6 Invalid class instantiation [45]: Cannot instantiate abstract class `Concrete7A` with abstract method `method1`.
"""
5 changes: 3 additions & 2 deletions conformance/results/pyright/generics_typevartuple_basic.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
conformant = "Partial"
notes = """
Does not enforce that tuples captured by TypeVarTuple are same length (spec bug?).
Does not enforce that tuples captured by TypeVarTuple are same type (spec bug?).
"""
output = """
Expand All @@ -20,7 +19,9 @@ 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:87:13 - error: "assert_type" mismatch: expected "tuple[int]" but received "tuple[tuple[Literal[0]], tuple[Literal[1]]]" (reportGeneralTypeIssues)
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"
  "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"
  "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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
conformant = "Partial"
notes = """
Incorrectly reports type incompatibility when generic class is specialized with `*tuple[Any, ...]`.
Incorrectly evaluates generic alias with TypeVarTuple if no type arguments are supplied.
Incorrectly evaluates tuple split across a TypeVarTuple and a TypeVar.
"""
output = """
generics_typevartuple_specialization.py:95:17 - error: "assert_type" mismatch: expected "tuple[Any, ...]" but received "tuple[Unknown, Unknown]" (reportGeneralTypeIssues)
generics_typevartuple_specialization.py:95:17 - error: "assert_type" mismatch: expected "tuple[Any, *tuple[Any, ...]]" but received "tuple[Unknown, Unknown]" (reportGeneralTypeIssues)
generics_typevartuple_specialization.py:109:18 - error: Type variable "Ts" has no meaning in this context (reportGeneralTypeIssues)
generics_typevartuple_specialization.py:109:18 - error: Could not specialize type "IntTupleGeneric[T@IntTupleGeneric]"
  Unpacked arguments cannot be used in type argument lists
Expand All @@ -15,11 +15,7 @@ generics_typevartuple_specialization.py:122:27 - error: Type argument list can h
generics_typevartuple_specialization.py:127:9 - error: Too few type arguments provided for "TA7[*Ts@TA7, T1@TA7, T2@TA7]"; expected 3 but received 2
generics_typevartuple_specialization.py:153:13 - error: Could not specialize type "TA9[*Ts@TA9, T1@TA9]"
  Unpacked arguments cannot be used in type argument lists
generics_typevartuple_specialization.py:156:65 - error: Could not specialize type "TA9[*Ts@TA9, T1@TA9]"
  Unpacked arguments cannot be used in type argument lists
generics_typevartuple_specialization.py:157:17 - error: "assert_type" mismatch: expected "tuple[*tuple[int, ...], int]" but received "tuple[Unknown]" (reportGeneralTypeIssues)
generics_typevartuple_specialization.py:159:17 - error: "assert_type" mismatch: expected "tuple[str, *tuple[int, ...], int]" but received "tuple[str, Unknown]" (reportGeneralTypeIssues)
generics_typevartuple_specialization.py:163:11 - error: Type variable "Ts2" has no meaning in this context (reportGeneralTypeIssues)
generics_typevartuple_specialization.py:163:11 - error: Could not specialize type "TA11[T@TA11, *Ts1@TA11]"
generics_typevartuple_specialization.py:163:14 - error: Could not specialize type "TA11[T@TA11, *Ts1@TA11]"
  Unpacked arguments cannot be used in type argument lists
"""
Loading

0 comments on commit c077170

Please sign in to comment.