Skip to content

Commit

Permalink
Added tests for "Type checker directives" section of spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
erictraut committed Dec 31, 2023
1 parent 786cc80 commit bbe8508
Show file tree
Hide file tree
Showing 41 changed files with 459 additions and 10 deletions.
10 changes: 10 additions & 0 deletions conformance/results/mypy/directives_assert_type.toml
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]
"""
16 changes: 16 additions & 0 deletions conformance/results/mypy/directives_cast.toml
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
"""
3 changes: 3 additions & 0 deletions conformance/results/mypy/directives_no_type_check.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conformant = "Pass"
output = """
"""
11 changes: 11 additions & 0 deletions conformance/results/mypy/directives_reveal_type.toml
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]
"""
3 changes: 3 additions & 0 deletions conformance/results/mypy/directives_type_checking.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conformant = "Pass"
output = """
"""
10 changes: 10 additions & 0 deletions conformance/results/mypy/directives_type_ignore.toml
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
"""
11 changes: 11 additions & 0 deletions conformance/results/mypy/directives_version_platform.toml
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]
"""
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.3973560333251953
test_duration = 0.4210233688354492
8 changes: 8 additions & 0 deletions conformance/results/pyre/directives_assert_type.toml
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.
"""
6 changes: 6 additions & 0 deletions conformance/results/pyre/directives_cast.toml
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.
"""
8 changes: 8 additions & 0 deletions conformance/results/pyre/directives_no_type_check.toml
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`.
"""
8 changes: 8 additions & 0 deletions conformance/results/pyre/directives_reveal_type.toml
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.
"""
3 changes: 3 additions & 0 deletions conformance/results/pyre/directives_type_checking.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conformant = "Pass"
output = """
"""
3 changes: 3 additions & 0 deletions conformance/results/pyre/directives_type_ignore.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conformant = "Pass"
output = """
"""
11 changes: 11 additions & 0 deletions conformance/results/pyre/directives_version_platform.toml
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`.
"""
2 changes: 1 addition & 1 deletion conformance/results/pyre/version.toml
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
8 changes: 8 additions & 0 deletions conformance/results/pyright/directives_assert_type.toml
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
"""
8 changes: 8 additions & 0 deletions conformance/results/pyright/directives_cast.toml
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)
"""
9 changes: 9 additions & 0 deletions conformance/results/pyright/directives_no_type_check.toml
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)
"""
9 changes: 9 additions & 0 deletions conformance/results/pyright/directives_reveal_type.toml
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
"""
3 changes: 3 additions & 0 deletions conformance/results/pyright/directives_type_checking.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conformant = "Pass"
output = """
"""
3 changes: 3 additions & 0 deletions conformance/results/pyright/directives_type_ignore.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conformant = "Pass"
output = """
"""
3 changes: 3 additions & 0 deletions conformance/results/pyright/directives_version_platform.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conformant = "Pass"
output = """
"""
2 changes: 1 addition & 1 deletion conformance/results/pyright/version.toml
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
18 changes: 18 additions & 0 deletions conformance/results/pytype/directives_assert_type.toml
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, _)
"""
11 changes: 11 additions & 0 deletions conformance/results/pytype/directives_cast.toml
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
"""
11 changes: 11 additions & 0 deletions conformance/results/pytype/directives_no_type_check.toml
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
"""
12 changes: 12 additions & 0 deletions conformance/results/pytype/directives_reveal_type.toml
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]
"""
3 changes: 3 additions & 0 deletions conformance/results/pytype/directives_type_checking.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conformant = "Pass"
output = """
"""
10 changes: 10 additions & 0 deletions conformance/results/pytype/directives_type_ignore.toml
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 conformance/results/pytype/directives_version_platform.toml
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
"""
4 changes: 2 additions & 2 deletions conformance/results/pytype/qualifiers_final_decorator.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ File "qualifiers_final_decorator.py", line 21, in <module>: Cannot subclass fina
File "qualifiers_final_decorator.py", line 52, in method4: bad return type [bad-return-type]
Expected: str
Actually returned: int
File "qualifiers_final_decorator.py", line 55, in <module>: Class Derived2 overrides final method method4, defined in base class Base2 [final-error]
File "qualifiers_final_decorator.py", line 55, in <module>: Class Derived2 overrides final method method1, defined in base class Base2 [final-error]
File "qualifiers_final_decorator.py", line 55, in <module>: Class Derived2 overrides final method method3, defined in base class Base2 [final-error]
File "qualifiers_final_decorator.py", line 55, in <module>: Class Derived2 overrides final method method1, defined in base class Base2 [final-error]
File "qualifiers_final_decorator.py", line 55, in <module>: Class Derived2 overrides final method method4, defined in base class Base2 [final-error]
File "qualifiers_final_decorator.py", line 55, in <module>: Class Derived2 overrides final method method2, defined in base class Base2 [final-error]
File "qualifiers_final_decorator.py", line 76, in method4: bad return type [bad-return-type]
Expected: str
Expand Down
2 changes: 1 addition & 1 deletion conformance/results/pytype/version.toml
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
Loading

0 comments on commit bbe8508

Please sign in to comment.