-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for "Type checker directives" section of spec.
- Loading branch information
Showing
41 changed files
with
459 additions
and
10 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,10 @@ | ||
conformant = "Pass" | ||
output = """ | ||
directives_assert_type.py:27: error: Expression is of type "int | str", not "int" [assert-type] | ||
directives_assert_type.py:28: error: Expression is of type "Any", not "int" [assert-type] | ||
directives_assert_type.py:30: error: "assert_type" expects 2 arguments [misc] | ||
directives_assert_type.py:30: error: Too few arguments for "assert_type" [call-arg] | ||
directives_assert_type.py:31: error: Expression is of type "Literal['']", not "int" [assert-type] | ||
directives_assert_type.py:32: error: "assert_type" expects 2 arguments [misc] | ||
directives_assert_type.py:32: error: Too many arguments for "assert_type" [call-arg] | ||
""" |
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,16 @@ | ||
conformant = "Pass" | ||
output = """ | ||
directives_cast.py:15: error: "cast" expects 2 arguments [misc] | ||
directives_cast.py:15: error: All overload variants of "cast" require at least one argument [call-overload] | ||
directives_cast.py:15: note: Possible overload variants: | ||
directives_cast.py:15: note: def [_T] cast(typ: type[_T], val: Any) -> _T | ||
directives_cast.py:15: note: def cast(typ: str, val: Any) -> Any | ||
directives_cast.py:15: note: def cast(typ: object, val: Any) -> Any | ||
directives_cast.py:16: error: Invalid type: try using Literal[1] instead? [valid-type] | ||
directives_cast.py:17: error: "cast" expects 2 arguments [misc] | ||
directives_cast.py:17: error: No overload variant of "cast" matches argument types "Any", "str", "str" [call-overload] | ||
directives_cast.py:17: note: Possible overload variants: | ||
directives_cast.py:17: note: def [_T] cast(typ: type[_T], val: Any) -> _T | ||
directives_cast.py:17: note: def cast(typ: str, val: Any) -> Any | ||
directives_cast.py:17: note: def cast(typ: object, val: Any) -> Any | ||
""" |
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,11 @@ | ||
conformant = "Pass" | ||
output = """ | ||
directives_reveal_type.py:14: note: Revealed type is "Union[builtins.int, builtins.str]" | ||
directives_reveal_type.py:15: note: Revealed type is "builtins.list[builtins.int]" | ||
directives_reveal_type.py:16: note: Revealed type is "Any" | ||
directives_reveal_type.py:17: note: Revealed type is "directives_reveal_type.ForwardReference" | ||
directives_reveal_type.py:19: error: "reveal_type" expects 1 argument [misc] | ||
directives_reveal_type.py:19: error: Too few arguments for "reveal_type" [call-arg] | ||
directives_reveal_type.py:20: error: "reveal_type" expects 1 argument [misc] | ||
directives_reveal_type.py:20: error: Too many arguments for "reveal_type" [call-arg] | ||
""" |
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,10 @@ | ||
conformant = "Partial" | ||
notes = """ | ||
Does not honor "# type: ignore" comment if comment includes additional text. | ||
""" | ||
output = """ | ||
directives_type_ignore.py:11: error: Invalid "type: ignore" comment [syntax] | ||
directives_type_ignore.py:11: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] | ||
directives_type_ignore.py:14: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] | ||
directives_type_ignore.py:14: note: Error code "assignment" not covered by "type: ignore" comment | ||
""" |
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,11 @@ | ||
conformant = "Pass" | ||
notes = """ | ||
Does not understand three-element form of sys.version checks. | ||
Does not understand os.name checks. | ||
""" | ||
output = """ | ||
directives_version_platform.py:19: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] | ||
directives_version_platform.py:27: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] | ||
directives_version_platform.py:40: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] | ||
directives_version_platform.py:45: error: Incompatible types in assignment (expression has type "str", variable has type "int") [assignment] | ||
""" |
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.3973560333251953 | ||
test_duration = 0.4210233688354492 |
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,8 @@ | ||
conformant = "Unsupported" | ||
notes = """ | ||
Does not understand "assert_type". | ||
""" | ||
output = """ | ||
directives_assert_type.py:30:4 Missing argument [20]: Call `assert_type` expects argument in position 0. | ||
directives_assert_type.py:32:4 Too many arguments [19]: Call `assert_type` expects 2 positional arguments, 3 were provided. | ||
""" |
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,6 @@ | ||
conformant = "Pass" | ||
output = """ | ||
directives_cast.py:15:7 Missing argument [20]: Call `cast` expects argument `typ`. | ||
directives_cast.py:16:12 Invalid type [31]: Expression `1` is not a valid type. | ||
directives_cast.py:17:7 Too many arguments [19]: Call `cast` expects 2 positional arguments, 3 were provided. | ||
""" |
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,8 @@ | ||
conformant = "Unsupported" | ||
notes = """ | ||
Does not honor @no_type_check decorator. | ||
""" | ||
output = """ | ||
directives_no_type_check.py:16:12 Unsupported operand [58]: `+` is not supported for operand types `int` and `str`. | ||
directives_no_type_check.py:17:4 Incompatible return type [7]: Expected `None` but got `int`. | ||
""" |
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,8 @@ | ||
conformant = "Unsupported" | ||
notes = """ | ||
Does not understand reveal_type call. | ||
""" | ||
output = """ | ||
directives_reveal_type.py:19:4 Missing argument [20]: Call `reveal_type` expects argument in position 0. | ||
directives_reveal_type.py:20:4 Too many arguments [19]: Call `reveal_type` expects 1 positional argument, 2 were provided. | ||
""" |
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,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,11 @@ | ||
conformant = "Partial" | ||
notes = """ | ||
Does not support sys.platform checks. | ||
Does not support os.name checks. | ||
""" | ||
output = """ | ||
directives_version_platform.py:31:4 Incompatible variable type [9]: val5 is declared to have type `int` but is used as type `str`. | ||
directives_version_platform.py:36:4 Incompatible variable type [9]: val6 is declared to have type `int` but is used as type `str`. | ||
directives_version_platform.py:40:4 Incompatible variable type [9]: val7 is declared to have type `int` but is used as type `str`. | ||
directives_version_platform.py:45:4 Incompatible variable type [9]: val8 is declared to have type `int` but is used as 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version = "pyre 0.9.19" | ||
test_duration = 1.5324349403381348 | ||
test_duration = 1.5986709594726562 |
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,8 @@ | ||
conformant = "Pass" | ||
output = """ | ||
directives_assert_type.py:27:17 - error: "assert_type" mismatch: expected "int" but received "int | str" (reportGeneralTypeIssues) | ||
directives_assert_type.py:28:17 - error: "assert_type" mismatch: expected "int" but received "Any" (reportGeneralTypeIssues) | ||
directives_assert_type.py:30:5 - error: "assert_type" expects two positional arguments | ||
directives_assert_type.py:31:17 - error: "assert_type" mismatch: expected "int" but received "Literal['']" (reportGeneralTypeIssues) | ||
directives_assert_type.py:32:5 - error: "assert_type" expects two positional arguments | ||
""" |
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,8 @@ | ||
conformant = "Pass" | ||
output = """ | ||
directives_cast.py:15:8 - error: No overloads for "cast" match the provided arguments | ||
Argument types: () (reportGeneralTypeIssues) | ||
directives_cast.py:16:13 - error: Expected type expression but received "Literal[1]" (reportGeneralTypeIssues) | ||
directives_cast.py:17:8 - error: No overloads for "cast" match the provided arguments | ||
Argument types: (type[int], Literal[''], Literal['']) (reportGeneralTypeIssues) | ||
""" |
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,9 @@ | ||
conformant = "Unsupported" | ||
notes = """ | ||
Intentionally does not honor @no_type_check decorator. | ||
""" | ||
output = """ | ||
directives_no_type_check.py:16:9 - error: Operator "+" not supported for types "int" and "str" (reportGeneralTypeIssues) | ||
directives_no_type_check.py:17:12 - error: Expression of type "Literal[1]" cannot be assigned to return type "None" | ||
"Literal[1]" is incompatible with "None" (reportGeneralTypeIssues) | ||
""" |
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,9 @@ | ||
conformant = "Pass" | ||
output = """ | ||
directives_reveal_type.py:14:17 - information: Type of "a" is "int | str" | ||
directives_reveal_type.py:15:17 - information: Type of "b" is "list[int]" | ||
directives_reveal_type.py:16:17 - information: Type of "c" is "Any" | ||
directives_reveal_type.py:17:17 - information: Type of "d" is "ForwardReference" | ||
directives_reveal_type.py:19:5 - error: Expected a single positional argument for "reveal_type" call | ||
directives_reveal_type.py:20:5 - error: Expected a single positional argument for "reveal_type" call | ||
""" |
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,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,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,2 +1,2 @@ | ||
version = "pyright 1.1.344" | ||
test_duration = 1.0535659790039062 | ||
test_duration = 1.028623104095459 |
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,18 @@ | ||
conformant = "Pass" | ||
output = """ | ||
File "directives_assert_type.py", line 27, in func1: Union[int, str] [assert-type] | ||
Expected: int | ||
Actual: Union[int, str] | ||
File "directives_assert_type.py", line 28, in func1: Any [assert-type] | ||
Expected: int | ||
Actual: Any | ||
File "directives_assert_type.py", line 30, in func1: Function assert_type expects 2 arg(s), got 0 [wrong-arg-count] | ||
Expected: (variable, type) | ||
Actually passed: () | ||
File "directives_assert_type.py", line 31, in func1: str [assert-type] | ||
Expected: int | ||
Actual: str | ||
File "directives_assert_type.py", line 32, in func1: Function assert_type expects 2 arg(s), got 3 [wrong-arg-count] | ||
Expected: (variable, type) | ||
Actually passed: (variable, 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,11 @@ | ||
conformant = "Partial" | ||
notes = """ | ||
Does not reject a call to "cast" with additional arguments. | ||
""" | ||
output = """ | ||
File "directives_cast.py", line 15, in <module>: Missing parameter 'typ' in call to function typing.cast [missing-parameter] | ||
Expected: (typ, val) | ||
Actually passed: () | ||
File "directives_cast.py", line 16, in <module>: Invalid type annotation '1' for typing.cast [invalid-annotation] | ||
Not 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,11 @@ | ||
conformant = "Unsupported" | ||
notes = """ | ||
Does not honor @no_type_check decorator. | ||
""" | ||
output = """ | ||
File "directives_no_type_check.py", line 16, in func1: unsupported operand type(s) for +: int and str [unsupported-operands] | ||
Function __add__ on int expects int | ||
File "directives_no_type_check.py", line 17, in func1: bad return type [bad-return-type] | ||
Expected: None | ||
Actually returned: int | ||
""" |
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,12 @@ | ||
conformant = "Partial" | ||
notes = """ | ||
Does not reject call to reveal_type with zero arguments. | ||
Does not reject call to reveal_type with too many arguments. | ||
""" | ||
output = """ | ||
File "directives_reveal_type.py", line 14, in func1: Union[int, str] [reveal-type] | ||
File "directives_reveal_type.py", line 15, in func1: List[int] [reveal-type] | ||
File "directives_reveal_type.py", line 16, in func1: Any [reveal-type] | ||
File "directives_reveal_type.py", line 17, in func1: ForwardReference [reveal-type] | ||
File "directives_reveal_type.py", line 20, in func1: Union[int, str] [reveal-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,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,10 @@ | ||
conformant = "Partial" | ||
notes = """ | ||
Does not honor "# type: ignore" comment if comment includes additional text. | ||
""" | ||
output = """ | ||
File "directives_type_ignore.py", line 11: Stray type comment: ignore - additional stuff [ignored-type-comment] | ||
File "directives_type_ignore.py", line 11, in <module>: Type annotation for y does not match type of assignment [annotation-type-mismatch] | ||
Annotation: int | ||
Assignment: str | ||
""" |
16 changes: 16 additions & 0 deletions
16
conformance/results/pytype/directives_version_platform.toml
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,16 @@ | ||
conformant = "Pass" | ||
notes = """ | ||
Does not understand three-element form of sys.version checks. | ||
Does not understand os.name checks. | ||
""" | ||
output = """ | ||
File "directives_version_platform.py", line 27, in <module>: Type annotation for val3 does not match type of assignment [annotation-type-mismatch] | ||
Annotation: int | ||
Assignment: str | ||
File "directives_version_platform.py", line 40, in <module>: Type annotation for val7 does not match type of assignment [annotation-type-mismatch] | ||
Annotation: int | ||
Assignment: str | ||
File "directives_version_platform.py", line 45, in <module>: Type annotation for val8 does not match type of assignment [annotation-type-mismatch] | ||
Annotation: int | ||
Assignment: 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
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 = "pytype 2023.12.18" | ||
test_duration = 57.623708963394165 | ||
test_duration = 64.40588402748108 |
Oops, something went wrong.