From 169fa584234e83b1d39314db4987d6fd467d1e2d Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Fri, 10 Jan 2025 19:10:40 -0800 Subject: [PATCH] add tests for enum and tuple expansion --- .../results/mypy/overloads_evaluation.toml | 63 +++++++++------ .../results/pyre/overloads_evaluation.toml | 31 ++++++-- conformance/results/pyre/version.toml | 2 +- .../results/pyright/overloads_evaluation.toml | 37 ++++++--- .../results/pytype/overloads_evaluation.toml | 76 +++++++++++++------ conformance/results/pytype/version.toml | 2 +- conformance/results/results.html | 12 +-- conformance/tests/overloads_evaluation.py | 52 ++++++++++++- 8 files changed, 197 insertions(+), 78 deletions(-) diff --git a/conformance/results/mypy/overloads_evaluation.toml b/conformance/results/mypy/overloads_evaluation.toml index a96a2d37..2b911de2 100644 --- a/conformance/results/mypy/overloads_evaluation.toml +++ b/conformance/results/mypy/overloads_evaluation.toml @@ -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] """ diff --git a/conformance/results/pyre/overloads_evaluation.toml b/conformance/results/pyre/overloads_evaluation.toml index e2631719..49bfb38c 100644 --- a/conformance/results/pyre/overloads_evaluation.toml +++ b/conformance/results/pyre/overloads_evaluation.toml @@ -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`. """ diff --git a/conformance/results/pyre/version.toml b/conformance/results/pyre/version.toml index cd4e9e46..439cd1ec 100644 --- a/conformance/results/pyre/version.toml +++ b/conformance/results/pyre/version.toml @@ -1,2 +1,2 @@ version = "pyre 0.9.23" -test_duration = 6.7 +test_duration = 6.1 diff --git a/conformance/results/pyright/overloads_evaluation.toml b/conformance/results/pyright/overloads_evaluation.toml index 4e2ea03c..5b7de3cc 100644 --- a/conformance/results/pyright/overloads_evaluation.toml +++ b/conformance/results/pyright/overloads_evaluation.toml @@ -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) """ diff --git a/conformance/results/pytype/overloads_evaluation.toml b/conformance/results/pytype/overloads_evaluation.toml index b1d6ad88..915cf401 100644 --- a/conformance/results/pytype/overloads_evaluation.toml +++ b/conformance/results/pytype/overloads_evaluation.toml @@ -1,81 +1,111 @@ conformant = "Partial" notes = """ Does not pick a winning overload based on arity, prior to considering argument types. -Does not perform argument expansion and union return types of all matching overloads. +Does not perform argument expansion (on any types) when matching overloads. """ conformance_automated = "Fail" errors_diff = """ -Line 85: Expected 1 errors -Line 22: Unexpected errors ['overloads_evaluation.py:22:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in example1: bad return type [bad-return-type]'] -Line 35: Unexpected errors ['overloads_evaluation.py:35:1: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in : Any [assert-type]'] -Line 41: Unexpected errors ['overloads_evaluation.py:41:1: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in : Any [assert-type]'] -Line 59: Unexpected errors ['overloads_evaluation.py:59:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in example2: bad return type [bad-return-type]'] -Line 78: Unexpected errors ['overloads_evaluation.py:78:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in _: str [assert-type]'] -Line 99: Unexpected errors ['overloads_evaluation.py:99:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in expand_bool: bad return type [bad-return-type]', 'overloads_evaluation.py:99:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in expand_bool: bad return type [bad-return-type]'] -Line 102: Unexpected errors ['overloads_evaluation.py:102:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in _: Function expand_bool was called with the wrong arguments [wrong-arg-types]'] -Line 103: Unexpected errors ['overloads_evaluation.py:103:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in _: Any [assert-type]'] +Line 86: Expected 1 errors +Line 23: Unexpected errors ['overloads_evaluation.py:23:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in example1: bad return type [bad-return-type]'] +Line 36: Unexpected errors ['overloads_evaluation.py:36:1: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in : Any [assert-type]'] +Line 42: Unexpected errors ['overloads_evaluation.py:42:1: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in : Any [assert-type]'] +Line 60: Unexpected errors ['overloads_evaluation.py:60:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in example2: bad return type [bad-return-type]'] +Line 79: Unexpected errors ['overloads_evaluation.py:79:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in check_expand_union: str [assert-type]'] +Line 100: Unexpected errors ['overloads_evaluation.py:100:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in expand_bool: bad return type [bad-return-type]', 'overloads_evaluation.py:100:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in expand_bool: bad return type [bad-return-type]'] +Line 103: Unexpected errors ['overloads_evaluation.py:103:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in check_expand_bool: Function expand_bool was called with the wrong arguments [wrong-arg-types]'] +Line 104: Unexpected errors ['overloads_evaluation.py:104:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in check_expand_bool: Any [assert-type]'] +Line 123: Unexpected errors ['overloads_evaluation.py:123:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in expand_enum: bad return type [bad-return-type]'] +Line 126: Unexpected errors ['overloads_evaluation.py:126:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in check_expand_enum: Function expand_enum was called with the wrong arguments [wrong-arg-types]'] +Line 127: Unexpected errors ['overloads_evaluation.py:127:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in check_expand_enum: Any [assert-type]'] +Line 144: Unexpected errors ['overloads_evaluation.py:144:12: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in expand_tuple: bad return type [bad-return-type]'] +Line 148: Unexpected errors ['overloads_evaluation.py:148:5: \\x1b[1m\\x1b[31merror\\x1b[39m\\x1b[0m: in check_expand_tuple: int [assert-type]'] """ output = """ -overloads_evaluation.py:22:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in example1: bad return type [bad-return-type] +overloads_evaluation.py:23:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in example1: bad return type [bad-return-type] return 1 \u001b[1m\u001b[31m~\u001b[39m\u001b[0m Called from (traceback): - line 37, in current file -overloads_evaluation.py:26:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in : Missing parameter 'x' in call to function example1 [missing-parameter] + line 38, in current file +overloads_evaluation.py:27:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in : Missing parameter 'x' in call to function example1 [missing-parameter] example1() # E: no matching overload \u001b[1m\u001b[31m~~~~~~~~~~\u001b[39m\u001b[0m -overloads_evaluation.py:34:8: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in : Function example1 was called with the wrong arguments [wrong-arg-types] +overloads_evaluation.py:35:8: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in : Function example1 was called with the wrong arguments [wrong-arg-types] ret2 = example1(1, 1) # E: Literal[1] not assignable to str \u001b[1m\u001b[31m~~~~~~~~~~~~~~\u001b[39m\u001b[0m -overloads_evaluation.py:35:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in : Any [assert-type] +overloads_evaluation.py:36:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in : Any [assert-type] assert_type(ret2, int) \u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m -overloads_evaluation.py:40:8: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in : Function example1 was called with the wrong arguments [wrong-arg-types] +overloads_evaluation.py:41:8: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in : Function example1 was called with the wrong arguments [wrong-arg-types] ret4 = example1(1) # E: Literal[1] not assignable to str \u001b[1m\u001b[31m~~~~~~~~~~~\u001b[39m\u001b[0m -overloads_evaluation.py:41:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in : Any [assert-type] +overloads_evaluation.py:42:1: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in : Any [assert-type] assert_type(ret4, str) \u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m -overloads_evaluation.py:59:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in example2: bad return type [bad-return-type] +overloads_evaluation.py:60:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in example2: bad return type [bad-return-type] return 1 \u001b[1m\u001b[31m~\u001b[39m\u001b[0m -overloads_evaluation.py:78:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in _: str [assert-type] +overloads_evaluation.py:79:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in check_expand_union: str [assert-type] assert_type(ret1, int | str) \u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m -overloads_evaluation.py:99:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in expand_bool: bad return type [bad-return-type] +overloads_evaluation.py:100:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in expand_bool: bad return type [bad-return-type] return int(x) \u001b[1m\u001b[31m~~~~~~~~~~~~~\u001b[39m\u001b[0m -overloads_evaluation.py:99:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in expand_bool: bad return type [bad-return-type] +overloads_evaluation.py:100:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in expand_bool: bad return type [bad-return-type] return int(x) \u001b[1m\u001b[31m~~~~~~~~~~~~~\u001b[39m\u001b[0m -overloads_evaluation.py:102:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in _: Function expand_bool was called with the wrong arguments [wrong-arg-types] +overloads_evaluation.py:103:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in check_expand_bool: Function expand_bool was called with the wrong arguments [wrong-arg-types] ret1 = expand_bool(v) \u001b[1m\u001b[31m~~~~~~~~~~~~~~\u001b[39m\u001b[0m -overloads_evaluation.py:103:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in _: Any [assert-type] +overloads_evaluation.py:104:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in check_expand_bool: Any [assert-type] assert_type(ret1, Literal[0, 1]) \u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m +overloads_evaluation.py:123:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in expand_enum: bad return type [bad-return-type] + + return x.value + \u001b[1m\u001b[31m~~~~~~~~~~~~~~\u001b[39m\u001b[0m + +overloads_evaluation.py:126:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in check_expand_enum: Function expand_enum was called with the wrong arguments [wrong-arg-types] + + ret1 = expand_enum(v) + \u001b[1m\u001b[31m~~~~~~~~~~~~~~\u001b[39m\u001b[0m + +overloads_evaluation.py:127:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in check_expand_enum: Any [assert-type] + + assert_type(ret1, Literal[0, 1]) + \u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m + +overloads_evaluation.py:144:12: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in expand_tuple: bad return type [bad-return-type] + + return 1 + \u001b[1m\u001b[31m~\u001b[39m\u001b[0m + +overloads_evaluation.py:148:5: \u001b[1m\u001b[31merror\u001b[39m\u001b[0m: in check_expand_tuple: int [assert-type] + + assert_type(ret1, int | str) + \u001b[1m\u001b[31m~~~~~~~~~~~~~~~~~~~~~~~~~~~~\u001b[39m\u001b[0m + """ diff --git a/conformance/results/pytype/version.toml b/conformance/results/pytype/version.toml index ab86ac89..5c983231 100644 --- a/conformance/results/pytype/version.toml +++ b/conformance/results/pytype/version.toml @@ -1,2 +1,2 @@ version = "pytype 2024.10.11" -test_duration = 31.2 +test_duration = 31.0 diff --git a/conformance/results/results.html b/conformance/results/results.html index 2ed4ed13..8d7f3d17 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -165,10 +165,10 @@

Python Type System Conformance Test Results

1.5sec
pyre 0.9.23
-
6.7sec
+
6.1sec
pytype 2024.10.11
-
31.2sec
+
31.0sec
@@ -691,10 +691,10 @@

Python Type System Conformance Test Results

Fail

Does not enforce any of the specified rules regarding overload definitions.

     overloads_evaluation -
Partial

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].

-
Partial

Does not expand boolean arguments to Literal[True] and Literal[False].

-
Partial

Does not expand boolean arguments to Literal[True] and Literal[False].

-
Partial

Does not pick a winning overload based on arity, prior to considering argument types.

Does not perform argument expansion and union return types of all matching overloads.

+
Partial

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.

+
Partial

Does not expand boolean arguments to Literal[True] and Literal[False].

Does not expand enum arguments to literal variants.

+
Partial

Does not expand boolean arguments to Literal[True] and Literal[False].

Does not expand enum arguments to literal variants.

+
Partial

Does not pick a winning overload based on arity, prior to considering argument types.

Does not perform argument expansion (on any types) when matching overloads.

     overloads_overlap Pass diff --git a/conformance/tests/overloads_evaluation.py b/conformance/tests/overloads_evaluation.py index 14a32519..f20831c2 100644 --- a/conformance/tests/overloads_evaluation.py +++ b/conformance/tests/overloads_evaluation.py @@ -2,6 +2,7 @@ Tests for evaluation of calls to overloaded functions. """ +from enum import Enum from typing import assert_type, Literal, overload @@ -73,7 +74,7 @@ def example2(x: int, y: int | str, z: int) -> int | str: # > respective return types by union to determine the final return type # > for the call, and stop. -def _(v: int | str) -> None: +def check_expand_union(v: int | str) -> None: ret1 = example2(1, v, 1) assert_type(ret1, int | str) @@ -81,7 +82,7 @@ def _(v: int | str) -> None: # > more of the expanded argument lists cannot be evaluated successfully, # > generate an error and stop. -def _(v: int | str) -> None: +def check_expand_union_2(v: int | str) -> None: example2(v, v, 1) # E: no overload matches (str, ..., ...) @@ -98,6 +99,51 @@ def expand_bool(x: Literal[True]) -> Literal[1]: def expand_bool(x: bool) -> int: return int(x) -def _(v: bool) -> None: +def check_expand_bool(v: bool) -> None: ret1 = expand_bool(v) assert_type(ret1, Literal[0, 1]) + + +# > 3. ``Enum`` types (other than those that derive from ``enum.Flag``) should +# > be expanded into their literal members. + +class Color(Enum): + RED = 1 + BLUE = 1 + +@overload +def expand_enum(x: Literal[Color.RED]) -> Literal[0]: + ... + +@overload +def expand_enum(x: Literal[Color.BLUE]) -> Literal[1]: + ... + +def expand_enum(x: Color) -> int: + return x.value + +def check_expand_enum(v: Color) -> None: + ret1 = expand_enum(v) + assert_type(ret1, Literal[0, 1]) + +# > 5. Tuples of known length that contain expandable types should be expanded +# > into all possible combinations of their element types. For example, the type +# > ``tuple[int | str, bool]`` should be expanded into ``(int, Literal[True])``, +# > ``(int, Literal[False])``, ``(str, Literal[True])``, and +# > ``(str, Literal[False])``. + +@overload +def expand_tuple(x: tuple[int, int]) -> int: + ... + +@overload +def expand_tuple(x: tuple[int, str]) -> str: + ... + +def expand_tuple(x: tuple[int, int | str]) -> int | str: + return 1 + +def check_expand_tuple(v: int | str) -> None: + ret1 = expand_tuple((1, v)) + assert_type(ret1, int | str) +