Skip to content

Commit

Permalink
add tests for enum and tuple expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Jan 11, 2025
1 parent f5bee93 commit 169fa58
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 78 deletions.
63 changes: 38 additions & 25 deletions conformance/results/mypy/overloads_evaluation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,47 @@ conformant = "Partial"
notes = """
Does not pick a winning overload based on arity, prior to considering argument types.
Does not expand boolean arguments to Literal[True] and Literal[False].
Does not expand enum arguments to literal variants.
Does not expand tuple arguments to possible combinations.
"""
conformance_automated = "Fail"
errors_diff = """
Line 35: Unexpected errors ['overloads_evaluation.py:35: error: Expression is of type "Any", not "int" [assert-type]']
Line 41: Unexpected errors ['overloads_evaluation.py:41: error: Expression is of type "Any", not "str" [assert-type]']
Line 102: Unexpected errors ['overloads_evaluation.py:102: error: No overload variant of "expand_bool" matches argument type "bool" [call-overload]']
Line 103: Unexpected errors ['overloads_evaluation.py:103: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]']
Line 36: Unexpected errors ['overloads_evaluation.py:36: error: Expression is of type "Any", not "int" [assert-type]']
Line 42: Unexpected errors ['overloads_evaluation.py:42: error: Expression is of type "Any", not "str" [assert-type]']
Line 103: Unexpected errors ['overloads_evaluation.py:103: error: No overload variant of "expand_bool" matches argument type "bool" [call-overload]']
Line 104: Unexpected errors ['overloads_evaluation.py:104: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]']
Line 126: Unexpected errors ['overloads_evaluation.py:126: error: No overload variant of "expand_enum" matches argument type "Color" [call-overload]']
Line 127: Unexpected errors ['overloads_evaluation.py:127: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]']
Line 147: Unexpected errors ['overloads_evaluation.py:147: error: Argument 1 to "expand_tuple" has incompatible type "tuple[int, int | str]"; expected "tuple[int, int]" [arg-type]']
Line 148: Unexpected errors ['overloads_evaluation.py:148: error: Expression is of type "int", not "int | str" [assert-type]']
"""
output = """
overloads_evaluation.py:26: error: All overload variants of "example1" require at least one argument [call-overload]
overloads_evaluation.py:26: note: Possible overload variants:
overloads_evaluation.py:26: note: def example1(x: int, y: str) -> int
overloads_evaluation.py:26: note: def example1(x: str) -> str
overloads_evaluation.py:34: error: No overload variant of "example1" matches argument types "int", "int" [call-overload]
overloads_evaluation.py:34: note: Possible overload variants:
overloads_evaluation.py:34: note: def example1(x: int, y: str) -> int
overloads_evaluation.py:34: note: def example1(x: str) -> str
overloads_evaluation.py:35: error: Expression is of type "Any", not "int" [assert-type]
overloads_evaluation.py:40: error: No overload variant of "example1" matches argument type "int" [call-overload]
overloads_evaluation.py:40: note: Possible overload variants:
overloads_evaluation.py:40: note: def example1(x: int, y: str) -> int
overloads_evaluation.py:40: note: def example1(x: str) -> str
overloads_evaluation.py:41: error: Expression is of type "Any", not "str" [assert-type]
overloads_evaluation.py:85: error: Argument 1 to "example2" has incompatible type "int | str"; expected "int" [arg-type]
overloads_evaluation.py:85: error: Argument 2 to "example2" has incompatible type "int | str"; expected "str" [arg-type]
overloads_evaluation.py:102: error: No overload variant of "expand_bool" matches argument type "bool" [call-overload]
overloads_evaluation.py:102: note: Possible overload variants:
overloads_evaluation.py:102: note: def expand_bool(x: Literal[False]) -> Literal[0]
overloads_evaluation.py:102: note: def expand_bool(x: Literal[True]) -> Literal[1]
overloads_evaluation.py:103: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]
overloads_evaluation.py:27: error: All overload variants of "example1" require at least one argument [call-overload]
overloads_evaluation.py:27: note: Possible overload variants:
overloads_evaluation.py:27: note: def example1(x: int, y: str) -> int
overloads_evaluation.py:27: note: def example1(x: str) -> str
overloads_evaluation.py:35: error: No overload variant of "example1" matches argument types "int", "int" [call-overload]
overloads_evaluation.py:35: note: Possible overload variants:
overloads_evaluation.py:35: note: def example1(x: int, y: str) -> int
overloads_evaluation.py:35: note: def example1(x: str) -> str
overloads_evaluation.py:36: error: Expression is of type "Any", not "int" [assert-type]
overloads_evaluation.py:41: error: No overload variant of "example1" matches argument type "int" [call-overload]
overloads_evaluation.py:41: note: Possible overload variants:
overloads_evaluation.py:41: note: def example1(x: int, y: str) -> int
overloads_evaluation.py:41: note: def example1(x: str) -> str
overloads_evaluation.py:42: error: Expression is of type "Any", not "str" [assert-type]
overloads_evaluation.py:86: error: Argument 1 to "example2" has incompatible type "int | str"; expected "int" [arg-type]
overloads_evaluation.py:86: error: Argument 2 to "example2" has incompatible type "int | str"; expected "str" [arg-type]
overloads_evaluation.py:103: error: No overload variant of "expand_bool" matches argument type "bool" [call-overload]
overloads_evaluation.py:103: note: Possible overload variants:
overloads_evaluation.py:103: note: def expand_bool(x: Literal[False]) -> Literal[0]
overloads_evaluation.py:103: note: def expand_bool(x: Literal[True]) -> Literal[1]
overloads_evaluation.py:104: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]
overloads_evaluation.py:126: error: No overload variant of "expand_enum" matches argument type "Color" [call-overload]
overloads_evaluation.py:126: note: Possible overload variants:
overloads_evaluation.py:126: note: def expand_enum(x: Literal[Color.RED]) -> Literal[0]
overloads_evaluation.py:126: note: def expand_enum(x: Literal[Color.BLUE]) -> Literal[1]
overloads_evaluation.py:127: error: Expression is of type "Any", not "Literal[0, 1]" [assert-type]
overloads_evaluation.py:147: error: Argument 1 to "expand_tuple" has incompatible type "tuple[int, int | str]"; expected "tuple[int, int]" [arg-type]
overloads_evaluation.py:148: error: Expression is of type "int", not "int | str" [assert-type]
"""
31 changes: 23 additions & 8 deletions conformance/results/pyre/overloads_evaluation.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
conformant = "Partial"
notes = """
Does not expand boolean arguments to Literal[True] and Literal[False].
Does not expand enum arguments to literal variants.
Does not expand tuple arguments to possible combinations.
"""
conformance_automated = "Fail"
errors_diff = """
Line 85: Expected 1 errors
Line 102: Unexpected errors ['overloads_evaluation.py:102:23 Incompatible parameter type [6]: In call `expand_bool`, for 1st positional argument, expected `typing_extensions.Literal[False]` but got `bool`.']
Line 103: Unexpected errors ['overloads_evaluation.py:103:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.']
Line 78: Unexpected errors ['overloads_evaluation.py:78:23 Incompatible parameter type [6]: In call `example2`, for 2nd positional argument, expected `str` but got `Union[int, str]`.']
Line 79: Unexpected errors ['overloads_evaluation.py:79:4 Assert type [70]: Expected `Union[int, str]` but got `str`.']
Line 103: Unexpected errors ['overloads_evaluation.py:103:23 Incompatible parameter type [6]: In call `expand_bool`, for 1st positional argument, expected `typing_extensions.Literal[False]` but got `bool`.']
Line 104: Unexpected errors ['overloads_evaluation.py:104:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.']
Line 126: Unexpected errors ['overloads_evaluation.py:126:23 Incompatible parameter type [6]: In call `expand_enum`, for 1st positional argument, expected `typing_extensions.Literal[Color.RED]` but got `Color`.']
Line 127: Unexpected errors ['overloads_evaluation.py:127:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.']
Line 147: Unexpected errors ['overloads_evaluation.py:147:24 Incompatible parameter type [6]: In call `expand_tuple`, for 1st positional argument, expected `Tuple[int, int]` but got `Tuple[int, Union[int, str]]`.']
Line 148: Unexpected errors ['overloads_evaluation.py:148:4 Assert type [70]: Expected `Union[int, str]` but got `int`.']
"""
output = """
overloads_evaluation.py:26:0 Missing argument [20]: Call `example1` expects argument `x`.
overloads_evaluation.py:34:19 Incompatible parameter type [6]: In call `example1`, for 2nd positional argument, expected `str` but got `int`.
overloads_evaluation.py:40:16 Incompatible parameter type [6]: In call `example1`, for 1st positional argument, expected `str` but got `int`.
overloads_evaluation.py:102:23 Incompatible parameter type [6]: In call `expand_bool`, for 1st positional argument, expected `typing_extensions.Literal[False]` but got `bool`.
overloads_evaluation.py:103:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.
overloads_evaluation.py:27:0 Missing argument [20]: Call `example1` expects argument `x`.
overloads_evaluation.py:35:19 Incompatible parameter type [6]: In call `example1`, for 2nd positional argument, expected `str` but got `int`.
overloads_evaluation.py:41:16 Incompatible parameter type [6]: In call `example1`, for 1st positional argument, expected `str` but got `int`.
overloads_evaluation.py:78:23 Incompatible parameter type [6]: In call `example2`, for 2nd positional argument, expected `str` but got `Union[int, str]`.
overloads_evaluation.py:79:4 Assert type [70]: Expected `Union[int, str]` but got `str`.
overloads_evaluation.py:86:13 Incompatible parameter type [6]: In call `example2`, for 1st positional argument, expected `int` but got `Union[int, str]`.
overloads_evaluation.py:86:16 Incompatible parameter type [6]: In call `example2`, for 2nd positional argument, expected `str` but got `Union[int, str]`.
overloads_evaluation.py:103:23 Incompatible parameter type [6]: In call `expand_bool`, for 1st positional argument, expected `typing_extensions.Literal[False]` but got `bool`.
overloads_evaluation.py:104:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.
overloads_evaluation.py:126:23 Incompatible parameter type [6]: In call `expand_enum`, for 1st positional argument, expected `typing_extensions.Literal[Color.RED]` but got `Color`.
overloads_evaluation.py:127:4 Assert type [70]: Expected `Union[typing_extensions.Literal[0], typing_extensions.Literal[1]]` but got `typing_extensions.Literal[0]`.
overloads_evaluation.py:147:24 Incompatible parameter type [6]: In call `expand_tuple`, for 1st positional argument, expected `Tuple[int, int]` but got `Tuple[int, Union[int, str]]`.
overloads_evaluation.py:148:4 Assert type [70]: Expected `Union[int, str]` but got `int`.
"""
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.23"
test_duration = 6.7
test_duration = 6.1
37 changes: 26 additions & 11 deletions conformance/results/pyright/overloads_evaluation.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
conformant = "Partial"
notes = """
Does not expand boolean arguments to Literal[True] and Literal[False].
Does not expand enum arguments to literal variants.
Does not expand tuple arguments to possible combinations.
"""
conformance_automated = "Fail"
errors_diff = """
Line 102: Unexpected errors ['overloads_evaluation.py:102:12 - error: No overloads for "expand_bool" match the provided arguments (reportCallIssue)', 'overloads_evaluation.py:102:24 - error: Argument of type "bool" cannot be assigned to parameter "x" of type "Literal[True]" in function "expand_bool"']
Line 103: Unexpected errors ['overloads_evaluation.py:103:17 - error: "assert_type" mismatch: expected "Literal[0, 1]" but received "Unknown" (reportAssertTypeFailure)']
Line 103: Unexpected errors ['overloads_evaluation.py:103:12 - error: No overloads for "expand_bool" match the provided arguments (reportCallIssue)', 'overloads_evaluation.py:103:24 - error: Argument of type "bool" cannot be assigned to parameter "x" of type "Literal[True]" in function "expand_bool"']
Line 104: Unexpected errors ['overloads_evaluation.py:104:17 - error: "assert_type" mismatch: expected "Literal[0, 1]" but received "Unknown" (reportAssertTypeFailure)']
Line 126: Unexpected errors ['overloads_evaluation.py:126:12 - error: No overloads for "expand_enum" match the provided arguments (reportCallIssue)', 'overloads_evaluation.py:126:24 - error: Argument of type "Color" cannot be assigned to parameter "x" of type "Literal[Color.BLUE]" in function "expand_enum"']
Line 127: Unexpected errors ['overloads_evaluation.py:127:17 - error: "assert_type" mismatch: expected "Literal[0, 1]" but received "Unknown" (reportAssertTypeFailure)']
Line 147: Unexpected errors ['overloads_evaluation.py:147:12 - error: No overloads for "expand_tuple" match the provided arguments (reportCallIssue)', 'overloads_evaluation.py:147:29 - error: Argument of type "tuple[Literal[1], int | str]" cannot be assigned to parameter "x" of type "tuple[int, str]" in function "expand_tuple"']
Line 148: Unexpected errors ['overloads_evaluation.py:148:17 - error: "assert_type" mismatch: expected "int | str" but received "Unknown" (reportAssertTypeFailure)']
"""
output = """
overloads_evaluation.py:26:1 - error: No overloads for "example1" match the provided arguments
overloads_evaluation.py:27:1 - error: No overloads for "example1" match the provided arguments
  Argument types: () (reportCallIssue)
overloads_evaluation.py:34:20 - error: Argument of type "Literal[1]" cannot be assigned to parameter "y" of type "str" in function "example1"
overloads_evaluation.py:35:20 - error: Argument of type "Literal[1]" cannot be assigned to parameter "y" of type "str" in function "example1"
  "Literal[1]" is not assignable to "str" (reportArgumentType)
overloads_evaluation.py:40:17 - error: Argument of type "Literal[1]" cannot be assigned to parameter "x" of type "str" in function "example1"
overloads_evaluation.py:41:17 - error: Argument of type "Literal[1]" cannot be assigned to parameter "x" of type "str" in function "example1"
  "Literal[1]" is not assignable to "str" (reportArgumentType)
overloads_evaluation.py:85:5 - error: No overloads for "example2" match the provided arguments (reportCallIssue)
overloads_evaluation.py:85:14 - error: Argument of type "int | str" cannot be assigned to parameter "x" of type "int" in function "example2"
overloads_evaluation.py:86:5 - error: No overloads for "example2" match the provided arguments (reportCallIssue)
overloads_evaluation.py:86:14 - error: Argument of type "int | str" cannot be assigned to parameter "x" of type "int" in function "example2"
  Type "int | str" is not assignable to type "int"
    "str" is not assignable to "int" (reportArgumentType)
overloads_evaluation.py:85:17 - error: Argument of type "int | str" cannot be assigned to parameter "y" of type "int" in function "example2"
overloads_evaluation.py:86:17 - error: Argument of type "int | str" cannot be assigned to parameter "y" of type "int" in function "example2"
  Type "int | str" is not assignable to type "int"
    "str" is not assignable to "int" (reportArgumentType)
overloads_evaluation.py:102:12 - error: No overloads for "expand_bool" match the provided arguments (reportCallIssue)
overloads_evaluation.py:102:24 - error: Argument of type "bool" cannot be assigned to parameter "x" of type "Literal[True]" in function "expand_bool"
overloads_evaluation.py:103:12 - error: No overloads for "expand_bool" match the provided arguments (reportCallIssue)
overloads_evaluation.py:103:24 - error: Argument of type "bool" cannot be assigned to parameter "x" of type "Literal[True]" in function "expand_bool"
  "bool" is not assignable to type "Literal[True]" (reportArgumentType)
overloads_evaluation.py:103:17 - error: "assert_type" mismatch: expected "Literal[0, 1]" but received "Unknown" (reportAssertTypeFailure)
overloads_evaluation.py:104:17 - error: "assert_type" mismatch: expected "Literal[0, 1]" but received "Unknown" (reportAssertTypeFailure)
overloads_evaluation.py:126:12 - error: No overloads for "expand_enum" match the provided arguments (reportCallIssue)
overloads_evaluation.py:126:24 - error: Argument of type "Color" cannot be assigned to parameter "x" of type "Literal[Color.BLUE]" in function "expand_enum"
  "Color" is not assignable to type "Literal[Color.BLUE]" (reportArgumentType)
overloads_evaluation.py:127:17 - error: "assert_type" mismatch: expected "Literal[0, 1]" but received "Unknown" (reportAssertTypeFailure)
overloads_evaluation.py:147:12 - error: No overloads for "expand_tuple" match the provided arguments (reportCallIssue)
overloads_evaluation.py:147:29 - error: Argument of type "tuple[Literal[1], int | str]" cannot be assigned to parameter "x" of type "tuple[int, str]" in function "expand_tuple"
  Type "int | str" is not assignable to type "str"
    "int" is not assignable to "str" (reportArgumentType)
overloads_evaluation.py:148:17 - error: "assert_type" mismatch: expected "int | str" but received "Unknown" (reportAssertTypeFailure)
"""
Loading

0 comments on commit 169fa58

Please sign in to comment.