Skip to content

Commit b729bfc

Browse files
authored
Added a few more overload evaluation tests. (#1957)
* Added a few more overload evaluation tests. These uncovered a few more cases where mypy and pyright do not conform to the standard. * Incorporated feedback from Carl's code review.
1 parent 2dea83d commit b729bfc

File tree

8 files changed

+347
-170
lines changed

8 files changed

+347
-170
lines changed

conformance/results/mypy/overloads_evaluation.toml

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,51 @@ notes = """
33
Does not expand boolean arguments to Literal[True] and Literal[False].
44
Does not expand enum arguments to literal variants.
55
Does not expand tuple arguments to possible combinations.
6+
Does not evaluate Any in some cases where overload is ambiguous.
7+
Evaluates Any in some cases where overload is not ambiguous.
68
"""
79
conformance_automated = "Fail"
810
errors_diff = """
9-
Line 106: Unexpected errors ['overloads_evaluation.py:106: error: No overload variant of "expand_bool" matches argument type "bool" [call-overload]']
10-
Line 107: Unexpected errors ['overloads_evaluation.py:107: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]']
11-
Line 129: Unexpected errors ['overloads_evaluation.py:129: error: No overload variant of "expand_enum" matches argument type "Color" [call-overload]']
12-
Line 130: Unexpected errors ['overloads_evaluation.py:130: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]']
13-
Line 169: Unexpected errors ['overloads_evaluation.py:169: error: Argument 1 to "expand_tuple" has incompatible type "tuple[int, int | str]"; expected "tuple[int, int]" [arg-type]']
14-
Line 170: Unexpected errors ['overloads_evaluation.py:170: error: Expression is of type "int", not "int | str" [assert-type]']
11+
Line 134: Unexpected errors ['overloads_evaluation.py:134: error: No overload variant of "expand_bool" matches argument type "bool" [call-overload]']
12+
Line 135: Unexpected errors ['overloads_evaluation.py:135: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]']
13+
Line 160: Unexpected errors ['overloads_evaluation.py:160: error: No overload variant of "expand_enum" matches argument type "Color" [call-overload]']
14+
Line 161: Unexpected errors ['overloads_evaluation.py:161: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]']
15+
Line 204: Unexpected errors ['overloads_evaluation.py:204: error: Argument 1 to "expand_tuple" has incompatible type "tuple[int, int | str]"; expected "tuple[int, int]" [arg-type]']
16+
Line 205: Unexpected errors ['overloads_evaluation.py:205: error: Expression is of type "int", not "int | str" [assert-type]']
17+
Line 264: Unexpected errors ['overloads_evaluation.py:264: error: Expression is of type "list[Any]", not "Any" [assert-type]']
18+
Line 280: Unexpected errors ['overloads_evaluation.py:280: error: Expression is of type "list[Any]", not "Any" [assert-type]']
19+
Line 301: Unexpected errors ['overloads_evaluation.py:301: error: Expression is of type "Any", not "float" [assert-type]']
20+
Line 345: Unexpected errors ['overloads_evaluation.py:345: error: Expression is of type "list[Any]", not "Any" [assert-type]']
1521
"""
1622
output = """
17-
overloads_evaluation.py:32: error: All overload variants of "example1" require at least one argument [call-overload]
18-
overloads_evaluation.py:32: note: Possible overload variants:
19-
overloads_evaluation.py:32: note: def example1(x: int, y: str) -> int
20-
overloads_evaluation.py:32: note: def example1(x: str) -> str
21-
overloads_evaluation.py:40: error: No overload variant of "example1" matches argument types "int", "int" [call-overload]
22-
overloads_evaluation.py:40: note: Possible overload variants:
23-
overloads_evaluation.py:40: note: def example1(x: int, y: str) -> int
24-
overloads_evaluation.py:40: note: def example1(x: str) -> str
25-
overloads_evaluation.py:45: error: No overload variant of "example1" matches argument type "int" [call-overload]
26-
overloads_evaluation.py:45: note: Possible overload variants:
27-
overloads_evaluation.py:45: note: def example1(x: int, y: str) -> int
28-
overloads_evaluation.py:45: note: def example1(x: str) -> str
29-
overloads_evaluation.py:89: error: Argument 1 to "example2" has incompatible type "int | str"; expected "int" [arg-type]
30-
overloads_evaluation.py:89: error: Argument 2 to "example2" has incompatible type "int | str"; expected "str" [arg-type]
31-
overloads_evaluation.py:106: error: No overload variant of "expand_bool" matches argument type "bool" [call-overload]
32-
overloads_evaluation.py:106: note: Possible overload variants:
33-
overloads_evaluation.py:106: note: def expand_bool(x: Literal[False]) -> Literal[0]
34-
overloads_evaluation.py:106: note: def expand_bool(x: Literal[True]) -> Literal[1]
35-
overloads_evaluation.py:107: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]
36-
overloads_evaluation.py:129: error: No overload variant of "expand_enum" matches argument type "Color" [call-overload]
37-
overloads_evaluation.py:129: note: Possible overload variants:
38-
overloads_evaluation.py:129: note: def expand_enum(x: Literal[Color.RED]) -> Literal[0]
39-
overloads_evaluation.py:129: note: def expand_enum(x: Literal[Color.BLUE]) -> Literal[1]
40-
overloads_evaluation.py:130: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]
41-
overloads_evaluation.py:169: error: Argument 1 to "expand_tuple" has incompatible type "tuple[int, int | str]"; expected "tuple[int, int]" [arg-type]
42-
overloads_evaluation.py:170: error: Expression is of type "int", not "int | str" [assert-type]
23+
overloads_evaluation.py:38: error: All overload variants of "example1_1" require at least one argument [call-overload]
24+
overloads_evaluation.py:38: note: Possible overload variants:
25+
overloads_evaluation.py:38: note: def example1_1(x: int, y: str) -> int
26+
overloads_evaluation.py:38: note: def example1_1(x: str) -> str
27+
overloads_evaluation.py:46: error: No overload variant of "example1_1" matches argument types "int", "int" [call-overload]
28+
overloads_evaluation.py:46: note: Possible overload variants:
29+
overloads_evaluation.py:46: note: def example1_1(x: int, y: str) -> int
30+
overloads_evaluation.py:46: note: def example1_1(x: str) -> str
31+
overloads_evaluation.py:51: error: No overload variant of "example1_1" matches argument type "int" [call-overload]
32+
overloads_evaluation.py:51: note: Possible overload variants:
33+
overloads_evaluation.py:51: note: def example1_1(x: int, y: str) -> int
34+
overloads_evaluation.py:51: note: def example1_1(x: str) -> str
35+
overloads_evaluation.py:115: error: Argument 1 to "example2" has incompatible type "int | str"; expected "int" [arg-type]
36+
overloads_evaluation.py:115: error: Argument 2 to "example2" has incompatible type "int | str"; expected "str" [arg-type]
37+
overloads_evaluation.py:134: error: No overload variant of "expand_bool" matches argument type "bool" [call-overload]
38+
overloads_evaluation.py:134: note: Possible overload variants:
39+
overloads_evaluation.py:134: note: def expand_bool(x: Literal[False]) -> Literal[0]
40+
overloads_evaluation.py:134: note: def expand_bool(x: Literal[True]) -> Literal[1]
41+
overloads_evaluation.py:135: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]
42+
overloads_evaluation.py:160: error: No overload variant of "expand_enum" matches argument type "Color" [call-overload]
43+
overloads_evaluation.py:160: note: Possible overload variants:
44+
overloads_evaluation.py:160: note: def expand_enum(x: Literal[Color.RED]) -> Literal[0]
45+
overloads_evaluation.py:160: note: def expand_enum(x: Literal[Color.BLUE]) -> Literal[1]
46+
overloads_evaluation.py:161: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]
47+
overloads_evaluation.py:204: error: Argument 1 to "expand_tuple" has incompatible type "tuple[int, int | str]"; expected "tuple[int, int]" [arg-type]
48+
overloads_evaluation.py:205: error: Expression is of type "int", not "int | str" [assert-type]
49+
overloads_evaluation.py:264: error: Expression is of type "list[Any]", not "Any" [assert-type]
50+
overloads_evaluation.py:280: error: Expression is of type "list[Any]", not "Any" [assert-type]
51+
overloads_evaluation.py:301: error: Expression is of type "Any", not "float" [assert-type]
52+
overloads_evaluation.py:345: error: Expression is of type "list[Any]", not "Any" [assert-type]
4353
"""

conformance/results/pyre/overloads_evaluation.toml

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,39 @@ Does not treat multiple matches due to gradual types as ambiguous.
99
"""
1010
conformance_automated = "Fail"
1111
errors_diff = """
12-
Line 81: Unexpected errors ['overloads_evaluation.py:81:23 Incompatible parameter type [6]: In call `example2`, for 2nd positional argument, expected `str` but got `Union[int, str]`.']
13-
Line 82: Unexpected errors ['overloads_evaluation.py:82:4 Assert type [70]: Expected `Union[int, str]` but got `str`.']
14-
Line 106: Unexpected errors ['overloads_evaluation.py:106:23 Incompatible parameter type [6]: In call `expand_bool`, for 1st positional argument, expected `typing_extensions.Literal[False]` but got `bool`.']
15-
Line 107: Unexpected errors ['overloads_evaluation.py:107:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.']
16-
Line 129: Unexpected errors ['overloads_evaluation.py:129:23 Incompatible parameter type [6]: In call `expand_enum`, for 1st positional argument, expected `typing_extensions.Literal[Color.RED]` but got `Color`.']
17-
Line 130: Unexpected errors ['overloads_evaluation.py:130:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.']
18-
Line 147: Unexpected errors ['overloads_evaluation.py:147:29 Incompatible parameter type [6]: In call `expand_type_union`, for 1st positional argument, expected `Type[int]` but got `Type[Union[int, str]]`.']
19-
Line 148: Unexpected errors ['overloads_evaluation.py:148:4 Assert type [70]: Expected `Union[int, str]` but got `int`.']
20-
Line 169: Unexpected errors ['overloads_evaluation.py:169:24 Incompatible parameter type [6]: In call `expand_tuple`, for 1st positional argument, expected `Tuple[int, int]` but got `Tuple[int, Union[int, str]]`.']
21-
Line 170: Unexpected errors ['overloads_evaluation.py:170:4 Assert type [70]: Expected `Union[int, str]` but got `int`.']
22-
Line 196: Unexpected errors ['overloads_evaluation.py:196:4 Assert type [70]: Expected `int` but got `str`.']
23-
Line 224: Unexpected errors ['overloads_evaluation.py:224:4 Assert type [70]: Expected `typing.Any` but got `int`.']
12+
Line 105: Unexpected errors ['overloads_evaluation.py:105:23 Incompatible parameter type [6]: In call `example2`, for 2nd positional argument, expected `str` but got `Union[int, str]`.']
13+
Line 106: Unexpected errors ['overloads_evaluation.py:106:4 Assert type [70]: Expected `Union[int, str]` but got `str`.']
14+
Line 134: Unexpected errors ['overloads_evaluation.py:134:23 Incompatible parameter type [6]: In call `expand_bool`, for 1st positional argument, expected `typing_extensions.Literal[False]` but got `bool`.']
15+
Line 135: Unexpected errors ['overloads_evaluation.py:135:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.']
16+
Line 160: Unexpected errors ['overloads_evaluation.py:160:23 Incompatible parameter type [6]: In call `expand_enum`, for 1st positional argument, expected `typing_extensions.Literal[Color.RED]` but got `Color`.']
17+
Line 161: Unexpected errors ['overloads_evaluation.py:161:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.']
18+
Line 180: Unexpected errors ['overloads_evaluation.py:180:29 Incompatible parameter type [6]: In call `expand_type_union`, for 1st positional argument, expected `Type[int]` but got `Type[Union[int, str]]`.']
19+
Line 181: Unexpected errors ['overloads_evaluation.py:181:4 Assert type [70]: Expected `Union[int, str]` but got `int`.']
20+
Line 204: Unexpected errors ['overloads_evaluation.py:204:24 Incompatible parameter type [6]: In call `expand_tuple`, for 1st positional argument, expected `Tuple[int, int]` but got `Tuple[int, Union[int, str]]`.']
21+
Line 205: Unexpected errors ['overloads_evaluation.py:205:4 Assert type [70]: Expected `Union[int, str]` but got `int`.']
22+
Line 234: Unexpected errors ['overloads_evaluation.py:234:4 Assert type [70]: Expected `int` but got `str`.']
23+
Line 264: Unexpected errors ['overloads_evaluation.py:264:4 Assert type [70]: Expected `typing.Any` but got `List[int]`.']
24+
Line 280: Unexpected errors ['overloads_evaluation.py:280:4 Assert type [70]: Expected `typing.Any` but got `List[int]`.']
25+
Line 345: Unexpected errors ['overloads_evaluation.py:345:4 Assert type [70]: Expected `typing.Any` but got `List[int]`.']
2426
"""
2527
output = """
26-
overloads_evaluation.py:32:0 Missing argument [20]: Call `example1` expects argument `x`.
27-
overloads_evaluation.py:40:12 Incompatible parameter type [6]: In call `example1`, for 2nd positional argument, expected `str` but got `int`.
28-
overloads_evaluation.py:45:9 Incompatible parameter type [6]: In call `example1`, for 1st positional argument, expected `str` but got `int`.
29-
overloads_evaluation.py:81:23 Incompatible parameter type [6]: In call `example2`, for 2nd positional argument, expected `str` but got `Union[int, str]`.
30-
overloads_evaluation.py:82:4 Assert type [70]: Expected `Union[int, str]` but got `str`.
31-
overloads_evaluation.py:89:13 Incompatible parameter type [6]: In call `example2`, for 1st positional argument, expected `int` but got `Union[int, str]`.
32-
overloads_evaluation.py:89:16 Incompatible parameter type [6]: In call `example2`, for 2nd positional argument, expected `str` but got `Union[int, str]`.
33-
overloads_evaluation.py:106:23 Incompatible parameter type [6]: In call `expand_bool`, for 1st positional argument, expected `typing_extensions.Literal[False]` but got `bool`.
34-
overloads_evaluation.py:107:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.
35-
overloads_evaluation.py:129:23 Incompatible parameter type [6]: In call `expand_enum`, for 1st positional argument, expected `typing_extensions.Literal[Color.RED]` but got `Color`.
36-
overloads_evaluation.py:130:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.
37-
overloads_evaluation.py:147:29 Incompatible parameter type [6]: In call `expand_type_union`, for 1st positional argument, expected `Type[int]` but got `Type[Union[int, str]]`.
38-
overloads_evaluation.py:148:4 Assert type [70]: Expected `Union[int, str]` but got `int`.
39-
overloads_evaluation.py:169:24 Incompatible parameter type [6]: In call `expand_tuple`, for 1st positional argument, expected `Tuple[int, int]` but got `Tuple[int, Union[int, str]]`.
40-
overloads_evaluation.py:170:4 Assert type [70]: Expected `Union[int, str]` but got `int`.
41-
overloads_evaluation.py:196:4 Assert type [70]: Expected `int` but got `str`.
42-
overloads_evaluation.py:224:4 Assert type [70]: Expected `typing.Any` but got `int`.
28+
overloads_evaluation.py:38:0 Missing argument [20]: Call `example1_1` expects argument `x`.
29+
overloads_evaluation.py:46:14 Incompatible parameter type [6]: In call `example1_1`, for 2nd positional argument, expected `str` but got `int`.
30+
overloads_evaluation.py:51:11 Incompatible parameter type [6]: In call `example1_1`, for 1st positional argument, expected `str` but got `int`.
31+
overloads_evaluation.py:105:23 Incompatible parameter type [6]: In call `example2`, for 2nd positional argument, expected `str` but got `Union[int, str]`.
32+
overloads_evaluation.py:106:4 Assert type [70]: Expected `Union[int, str]` but got `str`.
33+
overloads_evaluation.py:115:13 Incompatible parameter type [6]: In call `example2`, for 1st positional argument, expected `int` but got `Union[int, str]`.
34+
overloads_evaluation.py:115:16 Incompatible parameter type [6]: In call `example2`, for 2nd positional argument, expected `str` but got `Union[int, str]`.
35+
overloads_evaluation.py:134:23 Incompatible parameter type [6]: In call `expand_bool`, for 1st positional argument, expected `typing_extensions.Literal[False]` but got `bool`.
36+
overloads_evaluation.py:135:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.
37+
overloads_evaluation.py:160:23 Incompatible parameter type [6]: In call `expand_enum`, for 1st positional argument, expected `typing_extensions.Literal[Color.RED]` but got `Color`.
38+
overloads_evaluation.py:161:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.
39+
overloads_evaluation.py:180:29 Incompatible parameter type [6]: In call `expand_type_union`, for 1st positional argument, expected `Type[int]` but got `Type[Union[int, str]]`.
40+
overloads_evaluation.py:181:4 Assert type [70]: Expected `Union[int, str]` but got `int`.
41+
overloads_evaluation.py:204:24 Incompatible parameter type [6]: In call `expand_tuple`, for 1st positional argument, expected `Tuple[int, int]` but got `Tuple[int, Union[int, str]]`.
42+
overloads_evaluation.py:205:4 Assert type [70]: Expected `Union[int, str]` but got `int`.
43+
overloads_evaluation.py:234:4 Assert type [70]: Expected `int` but got `str`.
44+
overloads_evaluation.py:264:4 Assert type [70]: Expected `typing.Any` but got `List[int]`.
45+
overloads_evaluation.py:280:4 Assert type [70]: Expected `typing.Any` but got `List[int]`.
46+
overloads_evaluation.py:345:4 Assert type [70]: Expected `typing.Any` but got `List[int]`.
4347
"""

conformance/results/pyre/version.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "pyre 0.9.23"
2-
test_duration = 6.3
2+
test_duration = 6.4
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
conformant = "Pass"
2-
conformance_automated = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
Does not evaluate Any in some cases where overload is ambiguous.
4+
"""
5+
conformance_automated = "Fail"
36
errors_diff = """
7+
Line 280: Unexpected errors ['overloads_evaluation.py:280:17 - error: "assert_type" mismatch: expected "Any" but received "list[int]" (reportAssertTypeFailure)']
48
"""
59
output = """
6-
overloads_evaluation.py:32:1 - error: No overloads for "example1" match the provided arguments
10+
overloads_evaluation.py:38:1 - error: No overloads for "example1_1" match the provided arguments
711
  Argument types: () (reportCallIssue)
8-
overloads_evaluation.py:40:13 - error: Argument of type "Literal[1]" cannot be assigned to parameter "y" of type "str" in function "example1"
12+
overloads_evaluation.py:46:15 - error: Argument of type "Literal[1]" cannot be assigned to parameter "y" of type "str" in function "example1_1"
913
  "Literal[1]" is not assignable to "str" (reportArgumentType)
10-
overloads_evaluation.py:45:10 - error: Argument of type "Literal[1]" cannot be assigned to parameter "x" of type "str" in function "example1"
14+
overloads_evaluation.py:51:12 - error: Argument of type "Literal[1]" cannot be assigned to parameter "x" of type "str" in function "example1_1"
1115
  "Literal[1]" is not assignable to "str" (reportArgumentType)
12-
overloads_evaluation.py:89:5 - error: No overloads for "example2" match the provided arguments (reportCallIssue)
13-
overloads_evaluation.py:89:14 - error: Argument of type "int | str" cannot be assigned to parameter "x" of type "int" in function "example2"
16+
overloads_evaluation.py:115:5 - error: No overloads for "example2" match the provided arguments (reportCallIssue)
17+
overloads_evaluation.py:115:14 - error: Argument of type "int | str" cannot be assigned to parameter "x" of type "int" in function "example2"
1418
  Type "int | str" is not assignable to type "int"
1519
    "str" is not assignable to "int" (reportArgumentType)
16-
overloads_evaluation.py:89:17 - error: Argument of type "int | str" cannot be assigned to parameter "y" of type "int" in function "example2"
20+
overloads_evaluation.py:115:17 - error: Argument of type "int | str" cannot be assigned to parameter "y" of type "int" in function "example2"
1721
  Type "int | str" is not assignable to type "int"
1822
    "str" is not assignable to "int" (reportArgumentType)
23+
overloads_evaluation.py:280:17 - error: "assert_type" mismatch: expected "Any" but received "list[int]" (reportAssertTypeFailure)
1924
"""

0 commit comments

Comments
 (0)