Skip to content

Commit

Permalink
Added test cases for new "tuples" chapter. (#1609)
Browse files Browse the repository at this point in the history
* Added test cases for new "tuples" chapter.

* Fixed a bug in the tests and test results. Added a few missing tests.
  • Loading branch information
erictraut authored Jan 26, 2024
1 parent 02fc524 commit 62daab2
Show file tree
Hide file tree
Showing 31 changed files with 628 additions and 308 deletions.
2 changes: 1 addition & 1 deletion conformance/results/mypy/generics_typevartuple_unpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ notes = """
Does not reject multiple unpack operators in a tuple.
"""
output = """
generics_typevartuple_unpack.py:46: error: Argument 1 to "process_batch_channels" has incompatible type "Array[Batch]"; expected "Array[Batch, *tuple[Any, ...], Channels]" [arg-type]
generics_typevartuple_unpack.py:30: error: Argument 1 to "process_batch_channels" has incompatible type "Array[Batch]"; expected "Array[Batch, *tuple[Any, ...], Channels]" [arg-type]
"""
10 changes: 0 additions & 10 deletions conformance/results/mypy/specialtypes_tuple.toml

This file was deleted.

14 changes: 0 additions & 14 deletions conformance/results/mypy/specialtypes_tuple_unpack.toml

This file was deleted.

29 changes: 29 additions & 0 deletions conformance/results/mypy/tuples_type_compat.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
conformant = "Partial"
notes = """
Does not support tuple narrowing based on `len()` type guard (optional).
Incorrectly narrows tuple based on sequence patterns.
"""
output = """
tuples_type_compat.py:15: error: Incompatible types in assignment (expression has type "tuple[float, complex]", variable has type "tuple[int, int]") [assignment]
tuples_type_compat.py:29: error: Incompatible types in assignment (expression has type "tuple[int, ...]", variable has type "tuple[int, *tuple[int, ...]]") [assignment]
tuples_type_compat.py:32: error: Incompatible types in assignment (expression has type "tuple[int, *tuple[int, ...]]", variable has type "tuple[int]") [assignment]
tuples_type_compat.py:33: error: Incompatible types in assignment (expression has type "tuple[int, ...]", variable has type "tuple[int]") [assignment]
tuples_type_compat.py:43: error: Incompatible types in assignment (expression has type "tuple[int, ...]", variable has type "tuple[int]") [assignment]
tuples_type_compat.py:62: error: Incompatible types in assignment (expression has type "tuple[int, ...]", variable has type "tuple[int, int]") [assignment]
tuples_type_compat.py:95: error: Expression is of type "tuple[int] | tuple[str, str] | tuple[int, *tuple[str, ...], int]", not "tuple[int]" [assert-type]
tuples_type_compat.py:99: error: Expression is of type "tuple[int] | tuple[str, str] | tuple[int, *tuple[str, ...], int]", not "tuple[str, str] | tuple[int, int]" [assert-type]
tuples_type_compat.py:103: error: Expression is of type "tuple[int] | tuple[str, str] | tuple[int, *tuple[str, ...], int]", not "tuple[int, str, int]" [assert-type]
tuples_type_compat.py:117: error: Expression is of type "tuple[Never, int]", not "tuple[int | str, int]" [assert-type]
tuples_type_compat.py:136: error: Expression is of type "Sequence[object]", not "Sequence[complex | list[int]]" [assert-type]
tuples_type_compat.py:139: error: Expression is of type "Sequence[object]", not "Sequence[int | str]" [assert-type]
tuples_type_compat.py:144: error: Incompatible types in assignment (expression has type "tuple[int, str, str]", variable has type "tuple[int, str]") [assignment]
tuples_type_compat.py:149: error: Incompatible types in assignment (expression has type "tuple[int, int, str]", variable has type "tuple[int, *tuple[str, ...]]") [assignment]
tuples_type_compat.py:150: error: Incompatible types in assignment (expression has type "tuple[int, str, int]", variable has type "tuple[int, *tuple[str, ...]]") [assignment]
tuples_type_compat.py:156: error: Incompatible types in assignment (expression has type "tuple[int, str, str]", variable has type "tuple[int, *tuple[str, ...], int]") [assignment]
tuples_type_compat.py:157: error: Incompatible types in assignment (expression has type "tuple[int, str, str, float]", variable has type "tuple[int, *tuple[str, ...], int]") [assignment]
tuples_type_compat.py:162: error: Incompatible types in assignment (expression has type "tuple[int, str, int]", variable has type "tuple[*tuple[str, ...], int]") [assignment]
tuples_type_compat.py:163: error: Incompatible types in assignment (expression has type "tuple[str, str, float]", variable has type "tuple[*tuple[str, ...], int]") [assignment]
tuples_type_compat.py:168: error: Incompatible types in assignment (expression has type "tuple[str, str]", variable has type "tuple[str, str, int]") [assignment]
tuples_type_compat.py:171: error: Incompatible types in assignment (expression has type "tuple[str, str]", variable has type "tuple[str, str, str, *tuple[str, ...]]") [assignment]
tuples_type_compat.py:175: error: Incompatible types in assignment (expression has type "tuple[str, str]", variable has type "tuple[*tuple[str, ...], str, str, str]") [assignment]
"""
14 changes: 14 additions & 0 deletions conformance/results/mypy/tuples_type_form.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
conformant = "Pass"
output = """
tuples_type_form.py:12: error: Incompatible types in assignment (expression has type "tuple[int, int]", variable has type "tuple[int]") [assignment]
tuples_type_form.py:14: error: Incompatible types in assignment (expression has type "tuple[int]", variable has type "tuple[int, int]") [assignment]
tuples_type_form.py:15: error: Incompatible types in assignment (expression has type "tuple[int, str]", variable has type "tuple[int, int]") [assignment]
tuples_type_form.py:25: error: Incompatible types in assignment (expression has type "tuple[int]", variable has type "tuple[()]") [assignment]
tuples_type_form.py:36: error: Incompatible types in assignment (expression has type "tuple[int, int, int, str]", variable has type "tuple[int, ...]") [assignment]
tuples_type_form.py:40: error: Unexpected "..." [misc]
tuples_type_form.py:41: error: Unexpected "..." [misc]
tuples_type_form.py:42: error: Unexpected "..." [misc]
tuples_type_form.py:43: error: Unexpected "..." [misc]
tuples_type_form.py:44: error: Unpack is only valid in a variadic position [valid-type]
tuples_type_form.py:45: error: Unpack is only valid in a variadic position [valid-type]
"""
8 changes: 8 additions & 0 deletions conformance/results/mypy/tuples_unpacked.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
conformant = "Partial"
notes = """
"More than one unpack" error is missing a line number.
"""
output = """
tuples_unpacked.py: error: More than one Unpack in a type is not allowed [misc]
tuples_unpacked.py:58: error: More than one Unpack in a type is not allowed [misc]
"""
36 changes: 11 additions & 25 deletions conformance/results/pyre/generics_typevartuple_unpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,15 @@ notes = """
Does not support TypeVarTuple.
"""
output = """
generics_typevartuple_unpack.py:12:13 Invalid type [31]: Expression `tuple[(int, *tuple[(bool, bool)], str)]` is not a valid type.
generics_typevartuple_unpack.py:13:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[int], Type[bool], Type[bool], Type[str]]`.
generics_typevartuple_unpack.py:14: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[bool], Type[str]]`.
generics_typevartuple_unpack.py:14:25 Unable to concatenate tuple [60]: Expected to unpack an iterable, but got `typing.Type[tuple[Variable[_T_co](covariant)]]`.
generics_typevartuple_unpack.py:14: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], Type[bool]]`.
generics_typevartuple_unpack.py:15: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[int], Type[bool], *Tuple[typing.Any, ...]]`.
generics_typevartuple_unpack.py:15:25 Unable to concatenate tuple [60]: Expected to unpack an iterable, but got `typing.Type[tuple[Variable[_T_co](covariant)]]`.
generics_typevartuple_unpack.py:15:43 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[bool], Type[str]]`.
generics_typevartuple_unpack.py:21:13 Invalid type [31]: Expression `tuple[(int, *tuple[(bool, ...)], str)]` is not a valid type.
generics_typevartuple_unpack.py:22: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[int], *Tuple[typing.Any, ...], Type[str]]`.
generics_typevartuple_unpack.py:22:25 Unable to concatenate tuple [60]: Expected to unpack an iterable, but got `typing.Type[tuple[Variable[_T_co](covariant)]]`.
generics_typevartuple_unpack.py:22:37 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[bool], typing.Any]`.
generics_typevartuple_unpack.py:33:12 Invalid type [31]: Expression `typing.Generic[(*$local_generics_typevartuple_unpack$Ts)]` is not a valid type.
generics_typevartuple_unpack.py:37:30 Invalid type [31]: Expression `Array[(generics_typevartuple_unpack.Batch, *tuple[(typing.Any, ...)], generics_typevartuple_unpack.Channels)]` is not a valid type.
generics_typevartuple_unpack.py:37:30 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_unpack.py:42:7 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_unpack.py:42:49 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_unpack.py:42:76 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_unpack.py:52:29 Invalid type [31]: Expression `Array[(generics_typevartuple_unpack.Batch, *$local_generics_typevartuple_unpack$Shape)]` is not a valid type.
generics_typevartuple_unpack.py:52:29 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_unpack.py:56:28 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_unpack.py:60:13 Invalid type [31]: Expression `Array[(*tuple[(typing.Any, ...)])]` is not a valid type.
generics_typevartuple_unpack.py:60:13 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_unpack.py:67:6 Invalid type [31]: Expression `tuple[(*tuple[int], *tuple[int])]` is not a valid type.
generics_typevartuple_unpack.py:68:6 Invalid type [31]: Expression `tuple[(*tuple[(int, ...)], *tuple[int])]` is not a valid type.
generics_typevartuple_unpack.py:17:12 Invalid type [31]: Expression `typing.Generic[(*$local_generics_typevartuple_unpack$Ts)]` is not a valid type.
generics_typevartuple_unpack.py:21:30 Invalid type [31]: Expression `Array[(generics_typevartuple_unpack.Batch, *tuple[(typing.Any, ...)], generics_typevartuple_unpack.Channels)]` is not a valid type.
generics_typevartuple_unpack.py:21:30 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_unpack.py:26:7 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_unpack.py:26:49 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_unpack.py:26:76 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_unpack.py:36:29 Invalid type [31]: Expression `Array[(generics_typevartuple_unpack.Batch, *$local_generics_typevartuple_unpack$Shape)]` is not a valid type.
generics_typevartuple_unpack.py:36:29 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_unpack.py:40:28 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
generics_typevartuple_unpack.py:44:13 Invalid type [31]: Expression `Array[(*tuple[(typing.Any, ...)])]` is not a valid type.
generics_typevartuple_unpack.py:44:13 Invalid type parameters [24]: Non-generic type `Array` cannot take parameters.
"""
11 changes: 0 additions & 11 deletions conformance/results/pyre/specialtypes_tuple.toml

This file was deleted.

Loading

0 comments on commit 62daab2

Please sign in to comment.