Skip to content

Commit

Permalink
Added tests for the "Special types in annotations" section of the typ…
Browse files Browse the repository at this point in the history
…ing spec.
  • Loading branch information
erictraut committed Dec 31, 2023
1 parent 1dc37d7 commit 2e7ae17
Show file tree
Hide file tree
Showing 41 changed files with 1,174 additions and 10 deletions.
5 changes: 5 additions & 0 deletions conformance/results/mypy/specialtypes_any.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
conformant = "Pass"
output = """
specialtypes_any.py:37: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]
specialtypes_any.py:38: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]
"""
11 changes: 11 additions & 0 deletions conformance/results/mypy/specialtypes_never.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
conformant = "Partial"
notes = """
Does not reject NoReturn when used outside of return type annotation.
"""
output = """
specialtypes_never.py:19: error: Implicit return in function which does not return [misc]
specialtypes_never.py:85: error: Incompatible types in assignment (expression has type "list[NoReturn]", variable has type "list[int]") [assignment]
specialtypes_never.py:85: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
specialtypes_never.py:85: note: Consider using "Sequence" instead, which is covariant
specialtypes_never.py:104: error: Incompatible return value type (got "ClassC[NoReturn]", expected "ClassC[U]") [return-value]
"""
6 changes: 6 additions & 0 deletions conformance/results/mypy/specialtypes_none.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
conformant = "Pass"
output = """
specialtypes_none.py:21: error: Argument 1 to "func1" has incompatible type "type[None]"; expected "None" [arg-type]
specialtypes_none.py:27: error: Incompatible types in assignment (expression has type "None", variable has type "Iterable[Any]") [assignment]
specialtypes_none.py:41: error: Argument 1 to "func2" has incompatible type "None"; expected "type[None]" [arg-type]
"""
4 changes: 4 additions & 0 deletions conformance/results/mypy/specialtypes_promotions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
conformant = "Pass"
output = """
specialtypes_promotions.py:13: error: "float" has no attribute "numerator" [attr-defined]
"""
10 changes: 10 additions & 0 deletions conformance/results/mypy/specialtypes_tuple.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
conformant = "Pass"
output = """
specialtypes_tuple.py:12: error: Incompatible types in assignment (expression has type "tuple[int, int]", variable has type "tuple[int]") [assignment]
specialtypes_tuple.py:14: error: Incompatible types in assignment (expression has type "tuple[int]", variable has type "tuple[int, int]") [assignment]
specialtypes_tuple.py:15: error: Incompatible types in assignment (expression has type "tuple[int, str]", variable has type "tuple[int, int]") [assignment]
specialtypes_tuple.py:25: error: Incompatible types in assignment (expression has type "tuple[int]", variable has type "tuple[()]") [assignment]
specialtypes_tuple.py:36: error: Incompatible types in assignment (expression has type "tuple[int, int, int, str]", variable has type "tuple[int, ...]") [assignment]
specialtypes_tuple.py:42: error: Incompatible types in assignment (expression has type "tuple[int, ...]", variable has type "tuple[int]") [assignment]
specialtypes_tuple.py:43: error: Incompatible types in assignment (expression has type "tuple[int, ...]", variable has type "tuple[()]") [assignment]
"""
14 changes: 14 additions & 0 deletions conformance/results/mypy/specialtypes_tuple_unpack.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
conformant = "Pass"
output = """
specialtypes_tuple_unpack.py: error: More than one Unpack in a type is not allowed [misc]
specialtypes_tuple_unpack.py:7: error: Incompatible types in assignment (expression has type "tuple[int, str, str]", variable has type "tuple[int, str]") [assignment]
specialtypes_tuple_unpack.py:12: error: Incompatible types in assignment (expression has type "tuple[int, int, str]", variable has type "tuple[int, *tuple[str, ...]]") [assignment]
specialtypes_tuple_unpack.py:13: error: Incompatible types in assignment (expression has type "tuple[int, str, int]", variable has type "tuple[int, *tuple[str, ...]]") [assignment]
specialtypes_tuple_unpack.py:19: error: Incompatible types in assignment (expression has type "tuple[int, str, str]", variable has type "tuple[int, *tuple[str, ...], int]") [assignment]
specialtypes_tuple_unpack.py:20: error: Incompatible types in assignment (expression has type "tuple[int, str, str, float]", variable has type "tuple[int, *tuple[str, ...], int]") [assignment]
specialtypes_tuple_unpack.py:25: error: Incompatible types in assignment (expression has type "tuple[int, str, int]", variable has type "tuple[*tuple[str, ...], int]") [assignment]
specialtypes_tuple_unpack.py:26: error: Incompatible types in assignment (expression has type "tuple[str, str, float]", variable has type "tuple[*tuple[str, ...], int]") [assignment]
specialtypes_tuple_unpack.py:34: error: Incompatible types in assignment (expression has type "tuple[str, str]", variable has type "tuple[str, str, int]") [assignment]
specialtypes_tuple_unpack.py:37: error: Incompatible types in assignment (expression has type "tuple[str, str]", variable has type "tuple[str, str, str, *tuple[str, ...]]") [assignment]
specialtypes_tuple_unpack.py:41: error: Incompatible types in assignment (expression has type "tuple[str, str]", variable has type "tuple[*tuple[str, ...], str, str, str]") [assignment]
"""
20 changes: 20 additions & 0 deletions conformance/results/mypy/specialtypes_type.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
conformant = "Partial"
notes = """
Does not treat `type` same as `type[Any]` for assert_type.
Does not allow access to unknown attributes from object of type `type[Any]`.
"""
output = """
specialtypes_type.py:56: error: Argument 1 to "func4" has incompatible type "type[TeamUser]"; expected "type[BasicUser] | type[ProUser]" [arg-type]
specialtypes_type.py:70: error: Argument 1 to "func5" has incompatible type "<typing special form>"; expected "type[Never]" [arg-type]
specialtypes_type.py:76: error: type[...] must have exactly one type argument [valid-type]
specialtypes_type.py:84: error: Expression is of type "type", not "type[Any]" [assert-type]
specialtypes_type.py:99: error: "type" has no attribute "unknown" [attr-defined]
specialtypes_type.py:100: error: "type" has no attribute "unknown" [attr-defined]
specialtypes_type.py:117: error: "type[object]" has no attribute "unknown" [attr-defined]
specialtypes_type.py:120: error: "type[object]" has no attribute "unknown" [attr-defined]
specialtypes_type.py:139: error: Expression is of type "type", not "type[Any]" [assert-type]
specialtypes_type.py:143: error: "<typing special form>" has no attribute "unknown" [attr-defined]
specialtypes_type.py:144: error: "<typing special form>" has no attribute "unknown" [attr-defined]
specialtypes_type.py:145: error: "type[type]" has no attribute "unknown" [attr-defined]
specialtypes_type.py:146: error: "<typing special form>" has no attribute "unknown" [attr-defined]
"""
2 changes: 1 addition & 1 deletion conformance/results/mypy/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "mypy 1.8.0"
test_duration = 0.5543861389160156
test_duration = 0.5275311470031738
14 changes: 14 additions & 0 deletions conformance/results/pyre/specialtypes_any.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
conformant = "Partial"
notes = """
Does not treat missing type argument as Any in generic type.
Does not support Any as a base class.
"""
output = """
specialtypes_any.py:48:27 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T]]` but got `object`.
specialtypes_any.py:49:27 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Tuple[Type[Variable[_KT]], Type[Variable[_VT]]]` but got `Tuple[object, object]`.
specialtypes_any.py:62:28 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]`.
specialtypes_any.py:72:31 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Tuple[typing.Any, Type[Variable[$synthetic_attribute_resolution_variable]]]` but got `Tuple[typing.Any, object]`.
specialtypes_any.py:81:13 Invalid inheritance [39]: `typing.Any` is not a valid parent class.
specialtypes_any.py:87:12 Undefined attribute [16]: `ClassA` has no attribute `method2`.
specialtypes_any.py:88:12 Undefined attribute [16]: `ClassA` has no attribute `method3`.
"""
17 changes: 17 additions & 0 deletions conformance/results/pyre/specialtypes_never.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
conformant = "Partial"
notes = """
Does not reject NoReturn when used outside of return type annotation.
Does not treat Never as compatible with all other types.
"""
output = """
specialtypes_never.py:21:8 Incompatible return type [7]: Function declared non-returnable, but got `None`.
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.
specialtypes_never.py:67:4 Incompatible variable type [9]: v1 is declared to have type `int` but is used as type `Never`.
specialtypes_never.py:68:4 Incompatible variable type [9]: v2 is declared to have type `str` but is used as type `Never`.
specialtypes_never.py:69:4 Incompatible variable type [9]: v3 is declared to have type `List[str]` but is used as type `Never`.
specialtypes_never.py:85:4 Incompatible variable type [9]: v3 is declared to have type `List[int]` but is used as type `List[Never]`.
specialtypes_never.py:86:4 Incompatible variable type [9]: v4 is declared to have type `Never` but is used as type `NoReturn`.
specialtypes_never.py:95:4 Incompatible return type [7]: Expected `ClassB[Variable[U]]` but got `ClassB[Never]`.
specialtypes_never.py:104:4 Incompatible return type [7]: Expected `ClassC[Variable[U]]` but got `ClassC[Never]`.
"""
10 changes: 10 additions & 0 deletions conformance/results/pyre/specialtypes_none.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
conformant = "Partial"
notes = """
Does not correctly handle type annotation type[None].
"""
output = """
specialtypes_none.py:21:6 Incompatible parameter type [6]: In call `func1`, for 1st positional argument, expected `None` but got `Type[None]`.
specialtypes_none.py:27:0 Incompatible variable type [9]: none2 is declared to have type `Iterable[typing.Any]` but is used as type `None`.
specialtypes_none.py:36:27 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_meta](covariant)]` but got `None`.
specialtypes_none.py:41:6 Incompatible parameter type [6]: In call `func2`, for 1st positional argument, expected `Type[None]` but got `None`.
"""
6 changes: 6 additions & 0 deletions conformance/results/pyre/specialtypes_promotions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
conformant = "Partial"
notes = """
Does not reject use of attribute that is compatible only with float.
"""
output = """
"""
11 changes: 11 additions & 0 deletions conformance/results/pyre/specialtypes_tuple.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
conformant = "Partial"
notes = """
Does not report type violation when assigning tuple[T, ...] to tuple[T].
"""
output = """
specialtypes_tuple.py:12:0 Incompatible variable type [9]: t1 is declared to have type `Tuple[int]` but is used as type `Tuple[int, int]`.
specialtypes_tuple.py:14:0 Incompatible variable type [9]: t2 is declared to have type `Tuple[int, int]` but is used as type `Tuple[int]`.
specialtypes_tuple.py:15:0 Incompatible variable type [9]: t2 is declared to have type `Tuple[int, int]` but is used as type `Tuple[int, str]`.
specialtypes_tuple.py:25:0 Incompatible variable type [9]: t10 is declared to have type `Tuple[]` but is used as type `Tuple[int]`.
specialtypes_tuple.py:36:0 Incompatible variable type [9]: t20 is declared to have type `typing.Tuple[int, ...]` but is used as type `Tuple[int, int, int, str]`.
"""
43 changes: 43 additions & 0 deletions conformance/results/pyre/specialtypes_tuple_unpack.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
conformant = "Unsupported"
notes = """
Does not support unpacked tuple in type expression.
"""
output = """
specialtypes_tuple_unpack.py:6:4 Invalid type [31]: Expression `tuple[(int, *tuple[str])]` is not a valid type.
specialtypes_tuple_unpack.py:7:0 Incompatible variable type [9]: t1 is declared to have type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal['']]` but is used as type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal[''], typing_extensions.Literal['']]`.
specialtypes_tuple_unpack.py:9:0 Incompatible variable type [9]: t2 is declared to have type `Tuple[int, unknown]` but is used as type `Tuple[int]`.
specialtypes_tuple_unpack.py:9:4 Invalid type [31]: Expression `tuple[(int, *tuple[(str, ...)])]` is not a valid type.
specialtypes_tuple_unpack.py:10:0 Incompatible variable type [9]: t2 is declared to have type `Tuple[typing_extensions.Literal[1]]` but is used as type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal['']]`.
specialtypes_tuple_unpack.py:11:0 Incompatible variable type [9]: t2 is declared to have type `Tuple[typing_extensions.Literal[1]]` but is used as type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal[''], typing_extensions.Literal['']]`.
specialtypes_tuple_unpack.py:12:0 Incompatible variable type [9]: t2 is declared to have type `Tuple[typing_extensions.Literal[1]]` but is used as type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal[1], typing_extensions.Literal['']]`.
specialtypes_tuple_unpack.py:13:0 Incompatible variable type [9]: t2 is declared to have type `Tuple[typing_extensions.Literal[1]]` but is used as type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal[''], typing_extensions.Literal[1]]`.
specialtypes_tuple_unpack.py:16:0 Incompatible variable type [9]: t3 is declared to have type `Tuple[int, unknown, int]` but is used as type `Tuple[int, int]`.
specialtypes_tuple_unpack.py:16:4 Invalid type [31]: Expression `tuple[(int, *tuple[(str, ...)], int)]` is not a valid type.
specialtypes_tuple_unpack.py:17:0 Incompatible variable type [9]: t3 is declared to have type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal[2]]` but is used as type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal[''], typing_extensions.Literal[2]]`.
specialtypes_tuple_unpack.py:18:0 Incompatible variable type [9]: t3 is declared to have type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal[2]]` but is used as type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal[''], typing_extensions.Literal[''], typing_extensions.Literal[2]]`.
specialtypes_tuple_unpack.py:19:0 Incompatible variable type [9]: t3 is declared to have type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal[2]]` but is used as type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal[''], typing_extensions.Literal['']]`.
specialtypes_tuple_unpack.py:20:0 Incompatible variable type [9]: t3 is declared to have type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal[2]]` but is used as type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal[''], typing_extensions.Literal[''], float]`.
specialtypes_tuple_unpack.py:22:0 Incompatible variable type [9]: t4 is declared to have type `Tuple[unknown, int]` but is used as type `Tuple[int]`.
specialtypes_tuple_unpack.py:22:4 Invalid type [31]: Expression `tuple[(*tuple[(str, ...)], int)]` is not a valid type.
specialtypes_tuple_unpack.py:23:0 Incompatible variable type [9]: t4 is declared to have type `Tuple[typing_extensions.Literal[1]]` but is used as type `Tuple[typing_extensions.Literal[''], typing_extensions.Literal[1]]`.
specialtypes_tuple_unpack.py:24:0 Incompatible variable type [9]: t4 is declared to have type `Tuple[typing_extensions.Literal[1]]` but is used as type `Tuple[typing_extensions.Literal[''], typing_extensions.Literal[''], typing_extensions.Literal[1]]`.
specialtypes_tuple_unpack.py:25:0 Incompatible variable type [9]: t4 is declared to have type `Tuple[typing_extensions.Literal[1]]` but is used as type `Tuple[typing_extensions.Literal[1], typing_extensions.Literal[''], typing_extensions.Literal[1]]`.
specialtypes_tuple_unpack.py:26:0 Incompatible variable type [9]: t4 is declared to have type `Tuple[typing_extensions.Literal[1]]` but is used as type `Tuple[typing_extensions.Literal[''], typing_extensions.Literal[''], float]`.
specialtypes_tuple_unpack.py:28:4 Invalid type [31]: Expression `tuple[(*tuple[str], *tuple[int])]` is not a valid type.
specialtypes_tuple_unpack.py:29:4 Invalid type [31]: Expression `tuple[(*tuple[(str, ...)], *tuple[(int, ...)])]` is not a valid type.
specialtypes_tuple_unpack.py:33:4 Incompatible variable type [9]: t1 is declared to have type `Tuple[str, str, unknown]` but is used as type `Tuple[str, str]`.
specialtypes_tuple_unpack.py:33:8 Invalid type [31]: Expression `tuple[(str, str, *tuple[(int, ...)])]` is not a valid type.
specialtypes_tuple_unpack.py:34:4 Incompatible variable type [9]: t2 is declared to have type `Tuple[str, str, unknown]` but is used as type `Tuple[str, str]`.
specialtypes_tuple_unpack.py:34:8 Invalid type [31]: Expression `tuple[(str, str, *tuple[int])]` is not a valid type.
specialtypes_tuple_unpack.py:35:8 Invalid type [31]: Expression `tuple[(str, *tuple[(str, ...)])]` is not a valid type.
specialtypes_tuple_unpack.py:36:4 Incompatible variable type [9]: t4 is declared to have type `Tuple[str, str, unknown]` but is used as type `Tuple[str, str]`.
specialtypes_tuple_unpack.py:36:8 Invalid type [31]: Expression `tuple[(str, str, *tuple[(str, ...)])]` is not a valid type.
specialtypes_tuple_unpack.py:37:4 Incompatible variable type [9]: t5 is declared to have type `Tuple[str, str, str, unknown]` but is used as type `Tuple[str, str]`.
specialtypes_tuple_unpack.py:37:8 Invalid type [31]: Expression `tuple[(str, str, str, *tuple[(str, ...)])]` is not a valid type.
specialtypes_tuple_unpack.py:38:4 Incompatible variable type [9]: t6 is declared to have type `Tuple[str, unknown, str]` but is used as type `Tuple[str, str]`.
specialtypes_tuple_unpack.py:38:8 Invalid type [31]: Expression `tuple[(str, *tuple[(int, ...)], str)]` is not a valid type.
specialtypes_tuple_unpack.py:39:8 Invalid type [31]: Expression `tuple[(*tuple[(str, ...)], str)]` is not a valid type.
specialtypes_tuple_unpack.py:40:8 Invalid type [31]: Expression `tuple[(*tuple[(str, ...)], str)]` is not a valid type.
specialtypes_tuple_unpack.py:41:4 Incompatible variable type [9]: t9 is declared to have type `Tuple[unknown, str, str, str]` but is used as type `Tuple[str, str]`.
specialtypes_tuple_unpack.py:41:8 Invalid type [31]: Expression `tuple[(*tuple[(str, ...)], str, str, str)]` is not a valid type.
"""
Loading

0 comments on commit 2e7ae17

Please sign in to comment.