-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added remaining tests for "Type annotations" section of the typing spec.
- Loading branch information
Showing
32 changed files
with
721 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
conformant = "Pass" | ||
output = """ | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
conformant = "Partial" | ||
notes = """ | ||
Does not report error for a forward reference that is not enclosed in quotes. | ||
Does not report error for use of quoted type with "|" operator (runtime error). | ||
Incorrectly generates error for quoted type defined in class scope. | ||
""" | ||
output = """ | ||
annotations_forward_refs.py:41: error: Invalid type comment or annotation [valid-type] | ||
annotations_forward_refs.py:42: error: Invalid type comment or annotation [valid-type] | ||
annotations_forward_refs.py:43: error: Invalid type comment or annotation [valid-type] | ||
annotations_forward_refs.py:44: error: Invalid type comment or annotation [valid-type] | ||
annotations_forward_refs.py:45: error: Invalid type comment or annotation [valid-type] | ||
annotations_forward_refs.py:46: error: Invalid type comment or annotation [valid-type] | ||
annotations_forward_refs.py:47: error: Invalid type comment or annotation [valid-type] | ||
annotations_forward_refs.py:48: error: Invalid type comment or annotation [valid-type] | ||
annotations_forward_refs.py:49: error: Variable "annotations_forward_refs.var1" is not valid as a type [valid-type] | ||
annotations_forward_refs.py:49: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases | ||
annotations_forward_refs.py:50: error: Invalid type comment or annotation [valid-type] | ||
annotations_forward_refs.py:51: error: Invalid type comment or annotation [valid-type] | ||
annotations_forward_refs.py:52: error: Invalid type comment or annotation [valid-type] | ||
annotations_forward_refs.py:53: error: Invalid type comment or annotation [valid-type] | ||
annotations_forward_refs.py:54: error: Invalid type comment or annotation [valid-type] | ||
annotations_forward_refs.py:55: error: Module "types" is not valid as a type [valid-type] | ||
annotations_forward_refs.py:55: note: Perhaps you meant to use a protocol matching the module structure? | ||
annotations_forward_refs.py:80: error: Name "ClassF" is not defined [name-defined] | ||
annotations_forward_refs.py:87: error: Function "annotations_forward_refs.ClassD.int" is not valid as a type [valid-type] | ||
annotations_forward_refs.py:87: note: Perhaps you need "Callable[...]" or a callback protocol? | ||
annotations_forward_refs.py:89: error: Function "annotations_forward_refs.ClassD.int" is not valid as a type [valid-type] | ||
annotations_forward_refs.py:89: note: Perhaps you need "Callable[...]" or a callback protocol? | ||
annotations_forward_refs.py:93: error: Expression is of type int?, not "int" [assert-type] | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
conformant = "Partial" | ||
notes = """ | ||
Does not report incompatible Generator type in `yield from` statement. | ||
""" | ||
output = """ | ||
annotations_generators.py:50: error: Missing return statement [return] | ||
annotations_generators.py:53: error: Incompatible return value type (got "bool", expected "C") [return-value] | ||
annotations_generators.py:56: error: Incompatible types in "yield" (actual type "int", expected type "A") [misc] | ||
annotations_generators.py:65: error: Incompatible types in "yield" (actual type "int", expected type "A") [misc] | ||
annotations_generators.py:74: error: Incompatible types in "yield" (actual type "B", expected type "A") [misc] | ||
annotations_generators.py:85: error: The return type of a generator function should be "Generator" or one of its supertypes [misc] | ||
annotations_generators.py:90: error: The return type of an async generator function should be "AsyncGenerator" or one of its supertypes [misc] | ||
annotations_generators.py:117: error: Incompatible types in "yield from" (actual type "A", expected type "B") [misc] | ||
annotations_generators.py:118: error: Incompatible types in "yield from" (actual type "int", expected type "B") [misc] | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
conformant = "Pass" | ||
output = """ | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
conformant = "Pass" | ||
output = """ | ||
annotations_typeexpr.py:77: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:77: note: Suggestion: use eval[...] instead of eval(...) | ||
annotations_typeexpr.py:78: error: Bracketed expression "[...]" is not valid as a type [valid-type] | ||
annotations_typeexpr.py:79: error: Syntax error in type annotation [syntax] | ||
annotations_typeexpr.py:79: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn) | ||
annotations_typeexpr.py:80: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:81: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:82: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:83: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:84: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:85: error: Variable "annotations_typeexpr.var1" is not valid as a type [valid-type] | ||
annotations_typeexpr.py:85: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases | ||
annotations_typeexpr.py:86: error: Invalid type: try using Literal[True] instead? [valid-type] | ||
annotations_typeexpr.py:87: error: Invalid type: try using Literal[1] instead? [valid-type] | ||
annotations_typeexpr.py:88: error: Invalid type: try using Literal[-1] instead? [valid-type] | ||
annotations_typeexpr.py:89: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:90: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:88: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:88: note: Suggestion: use eval[...] instead of eval(...) | ||
annotations_typeexpr.py:89: error: Bracketed expression "[...]" is not valid as a type [valid-type] | ||
annotations_typeexpr.py:90: error: Syntax error in type annotation [syntax] | ||
annotations_typeexpr.py:90: note: Suggestion: Use Tuple[T1, ..., Tn] instead of (T1, ..., Tn) | ||
annotations_typeexpr.py:91: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:92: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:93: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:94: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:95: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:96: error: Variable "annotations_typeexpr.var1" is not valid as a type [valid-type] | ||
annotations_typeexpr.py:96: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases | ||
annotations_typeexpr.py:97: error: Invalid type: try using Literal[True] instead? [valid-type] | ||
annotations_typeexpr.py:98: error: Invalid type: try using Literal[1] instead? [valid-type] | ||
annotations_typeexpr.py:99: error: Invalid type: try using Literal[-1] instead? [valid-type] | ||
annotations_typeexpr.py:100: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:101: error: Invalid type comment or annotation [valid-type] | ||
annotations_typeexpr.py:102: error: Module "types" is not valid as a type [valid-type] | ||
annotations_typeexpr.py:102: note: Perhaps you meant to use a protocol matching the module structure? | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version = "mypy 1.8.0" | ||
test_duration = 0.3901679515838623 | ||
test_duration = 0.5739729404449463 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
conformant = "Partial" | ||
notes = """ | ||
Does not evaluate correct type for async function. | ||
""" | ||
output = """ | ||
annotations_coroutines.py:19:45 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Tuple[Type[Variable[_T_co](covariant)], Type[Variable[_T_contra](contravariant)], Type[Variable[_V_co](covariant)]]` but got `Tuple[object, object, Type[str]]`. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
conformant = "Partial" | ||
notes = """ | ||
Does not report error for a forward reference that is not enclosed in quotes. | ||
Does not report error for use of quoted type with "|" operator (runtime error). | ||
Does not reject f-string in quoted type annotation. | ||
Incorrectly generates error for quoted type defined in class scope. | ||
Does not generate error for unquoted type defined in class scope. | ||
""" | ||
output = """ | ||
annotations_forward_refs.py:19:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T]]` but got `UnionType`. | ||
annotations_forward_refs.py:41:8 Undefined or invalid type [11]: Annotation `eval(.join(map(chr, [105, 110, 116])))` is not defined as a type. | ||
annotations_forward_refs.py:42:8 Invalid type [31]: Expression `"[int, str]"` is not a valid type. | ||
annotations_forward_refs.py:43:8 Invalid type [31]: Expression `"(int, str)"` is not a valid type. | ||
annotations_forward_refs.py:44:8 Undefined or invalid type [11]: Annotation `comprehension(int for generators(generator($target$i in range(1) if )))` is not defined as a type. | ||
annotations_forward_refs.py:45:8 Invalid type [31]: Expression `"{ }"` is not a valid type. | ||
annotations_forward_refs.py:46:8 Undefined or invalid type [11]: Annotation `lambda () (int)()` is not defined as a type. | ||
annotations_forward_refs.py:47:8 Invalid type [31]: Expression `[int][0]` is not a valid type. | ||
annotations_forward_refs.py:48:8 Invalid type [31]: Expression `"int if 1 < 3 else str"` is not a valid type. | ||
annotations_forward_refs.py:49:8 Undefined or invalid type [11]: Annotation `var1` is not defined as a type. | ||
annotations_forward_refs.py:50:9 Invalid type [31]: Expression `"True"` is not a valid type. | ||
annotations_forward_refs.py:51:9 Invalid type [31]: Expression `"1"` is not a valid type. | ||
annotations_forward_refs.py:52:9 Invalid type [31]: Expression `"-1"` is not a valid type. | ||
annotations_forward_refs.py:53:9 Invalid type [31]: Expression `"int or str"` is not a valid type. | ||
annotations_forward_refs.py:55:9 Undefined or invalid type [11]: Annotation `types` is not defined as a type. | ||
annotations_forward_refs.py:77:0 Uninitialized attribute [13]: Attribute `ClassC` is declared in class `ClassD` to have type `ClassC` but is never initialized. | ||
annotations_forward_refs.py:80:12 Undefined or invalid type [11]: Annotation `ClassF` is not defined as a type. | ||
annotations_forward_refs.py:87:7 Undefined or invalid type [11]: Annotation `ClassD.int` is not defined as a type. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
conformant = "Partial" | ||
notes = """ | ||
Does not report invalid return type for generator when function implicitly returns None. | ||
Incorrectly evaluates type of call to async generator. | ||
""" | ||
output = """ | ||
annotations_generators.py:53:8 Incompatible return type [7]: Expected `Generator[A, B, C]` but got `Generator[typing.Any, typing.Any, bool]`. | ||
annotations_generators.py:56:8 Incompatible return type [7]: Expected `Generator[A, B, C]` but got `Generator[int, typing.Any, typing.Any]`. | ||
annotations_generators.py:65:8 Incompatible return type [7]: Expected `Generator[A, int, typing.Any]` but got `Generator[int, typing.Any, typing.Any]`. | ||
annotations_generators.py:74:4 Incompatible return type [7]: Expected `Iterator[A]` but got `Generator[B, typing.Any, typing.Any]`. | ||
annotations_generators.py:86:4 Incompatible return type [7]: Expected `int` but got `Generator[None, typing.Any, typing.Any]`. | ||
annotations_generators.py:87:4 Incompatible return type [7]: Expected `int` but got `Generator[typing.Any, typing.Any, int]`. | ||
annotations_generators.py:90:0 Incompatible async generator return type [57]: Expected return annotation to be AsyncGenerator or a superclass but got `int`. | ||
annotations_generators.py:91:4 Incompatible return type [7]: Expected `int` but got `AsyncGenerator[None, typing.Any]`. | ||
annotations_generators.py:117:4 Incompatible return type [7]: Expected `Iterator[B]` but got `Generator[A, None, typing.Any]`. | ||
annotations_generators.py:118:4 Incompatible return type [7]: Expected `Iterator[B]` but got `Generator[int, None, typing.Any]`. | ||
annotations_generators.py:134:4 Incompatible return type [7]: Expected `Generator[None, str, None]` but got `Generator[None, int, typing.Any]`. | ||
annotations_generators.py:166:35 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Tuple[Type[Variable[_T_co](covariant)], Type[Variable[_T_contra](contravariant)]]` but got `Tuple[Type[str], None]`. | ||
annotations_generators.py:173:35 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Tuple[Type[Variable[_T_co](covariant)], Type[Variable[_T_contra](contravariant)]]` but got `Tuple[Type[str], None]`. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
conformant = "Pass" | ||
output = """ | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
conformant = "Pass" | ||
output = """ | ||
annotations_typeexpr.py:65:26 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T]]` but got `object`. | ||
annotations_typeexpr.py:67:27 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]`. | ||
annotations_typeexpr.py:77:8 Invalid type [31]: Expression `eval("".join(map(chr, [105, 110, 116])))` is not a valid type. | ||
annotations_typeexpr.py:78:8 Invalid type [31]: Expression `[int, str]` is not a valid type. | ||
annotations_typeexpr.py:79:8 Invalid type [31]: Expression `(int, str)` is not a valid type. | ||
annotations_typeexpr.py:80:8 Invalid type [31]: Expression `comprehension(int for generators(generator($target$i in range(1) if )))` is not a valid type. | ||
annotations_typeexpr.py:81:8 Invalid type [31]: Expression `{ }` is not a valid type. | ||
annotations_typeexpr.py:82:8 Invalid type [31]: Expression `lambda () (int)()` is not a valid type. | ||
annotations_typeexpr.py:83:8 Invalid type [31]: Expression `[int][0]` is not a valid type. | ||
annotations_typeexpr.py:84:8 Invalid type [31]: Expression `int if 1 < 3 else str` is not a valid type. | ||
annotations_typeexpr.py:85:8 Undefined or invalid type [11]: Annotation `var1` is not defined as a type. | ||
annotations_typeexpr.py:86:9 Invalid type [31]: Expression `True` is not a valid type. | ||
annotations_typeexpr.py:87:9 Invalid type [31]: Expression `1` is not a valid type. | ||
annotations_typeexpr.py:88:9 Invalid type [31]: Expression `-1` is not a valid type. | ||
annotations_typeexpr.py:89:9 Invalid type [31]: Expression `int or str` is not a valid type. | ||
annotations_typeexpr.py:90:9 Invalid type [31]: Expression `"int"` is not a valid type. | ||
annotations_typeexpr.py:75:26 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T]]` but got `object`. | ||
annotations_typeexpr.py:77:27 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]`. | ||
annotations_typeexpr.py:88:8 Invalid type [31]: Expression `eval("".join(map(chr, [105, 110, 116])))` is not a valid type. | ||
annotations_typeexpr.py:89:8 Invalid type [31]: Expression `[int, str]` is not a valid type. | ||
annotations_typeexpr.py:90:8 Invalid type [31]: Expression `(int, str)` is not a valid type. | ||
annotations_typeexpr.py:91:8 Invalid type [31]: Expression `comprehension(int for generators(generator($target$i in range(1) if )))` is not a valid type. | ||
annotations_typeexpr.py:92:8 Invalid type [31]: Expression `{ }` is not a valid type. | ||
annotations_typeexpr.py:93:8 Invalid type [31]: Expression `lambda () (int)()` is not a valid type. | ||
annotations_typeexpr.py:94:8 Invalid type [31]: Expression `[int][0]` is not a valid type. | ||
annotations_typeexpr.py:95:8 Invalid type [31]: Expression `int if 1 < 3 else str` is not a valid type. | ||
annotations_typeexpr.py:96:8 Undefined or invalid type [11]: Annotation `var1` is not defined as a type. | ||
annotations_typeexpr.py:97:9 Invalid type [31]: Expression `True` is not a valid type. | ||
annotations_typeexpr.py:98:9 Invalid type [31]: Expression `1` is not a valid type. | ||
annotations_typeexpr.py:99:9 Invalid type [31]: Expression `-1` is not a valid type. | ||
annotations_typeexpr.py:100:9 Invalid type [31]: Expression `int or str` is not a valid type. | ||
annotations_typeexpr.py:101:9 Invalid type [31]: Expression `"int"` is not a valid type. | ||
annotations_typeexpr.py:102:9 Undefined or invalid type [11]: Annotation `types` is not defined as a type. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version = "pyre 0.9.19" | ||
test_duration = 1.8171961307525635 | ||
test_duration = 1.835569143295288 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
conformant = "Pass" | ||
output = """ | ||
""" |
Oops, something went wrong.