From bd79ac256478f643f3ae6814f5d0a3259b6bdc02 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 8 Apr 2024 21:30:05 -0400 Subject: [PATCH 1/2] Conformance tests: Ignore overlapping overload errors in LiteralString Part of #1692 --- conformance/results/mypy/literals_literalstring.toml | 2 +- conformance/results/pyright/literals_literalstring.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/conformance/results/mypy/literals_literalstring.toml b/conformance/results/mypy/literals_literalstring.toml index 0e7ae143a..98ab2a619 100644 --- a/conformance/results/mypy/literals_literalstring.toml +++ b/conformance/results/mypy/literals_literalstring.toml @@ -19,7 +19,7 @@ Line 66: Expected 1 errors Line 120: Expected 1 errors Line 134: Expected 1 errors Line 166: Expected 1 errors -Line 142: Unexpected errors ['literals_literalstring.py:142: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]', 'literals_literalstring.py:142: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [overload-overlap]'] Line 152: Unexpected errors ["literals_literalstring.py:152: error: Overloaded function signature 3 will never be matched: signature 2's parameter type(s) are the same or broader [misc]"] Line 162: Unexpected errors ['literals_literalstring.py:162: error: Expression is of type "bool", not "str" [assert-type]'] """ +ignore_errors = ["overload-overlap"] diff --git a/conformance/results/pyright/literals_literalstring.toml b/conformance/results/pyright/literals_literalstring.toml index 2e42e81ec..5d507c8ee 100644 --- a/conformance/results/pyright/literals_literalstring.toml +++ b/conformance/results/pyright/literals_literalstring.toml @@ -23,7 +23,7 @@ literals_literalstring.py:166:21 - error: Expression of type "list[LiteralString     Type parameter "_T@list" is invariant, but "LiteralString" is not the same as "str"     Consider switching from "list" to "Sequence" which is covariant (reportAssignmentType) """ -conformance_automated = "Fail" +conformance_automated = "Pass" errors_diff = """ -Line 142: Unexpected errors ['literals_literalstring.py:142:5 - error: Overload 1 for "func8" overlaps overload 2 and returns an incompatible type (reportOverlappingOverload)', 'literals_literalstring.py:142:5 - error: Overload 1 for "func8" overlaps overload 3 and returns an incompatible type (reportOverlappingOverload)'] """ +ignore_errors = ["reportOverlappingOverload"] From db68e8c49fffa2f0c9f87aec964d44b8f4a4df13 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 10 Apr 2024 09:44:18 -0400 Subject: [PATCH 2/2] Avoid overlapping overloads --- .../results/mypy/literals_literalstring.toml | 13 +++++-------- .../results/pyre/literals_literalstring.toml | 2 +- .../results/pyright/aliases_explicit.toml | 4 +--- .../results/pyright/aliases_type_statement.toml | 4 +--- .../results/pyright/aliases_typealiastype.toml | 4 +--- .../pyright/annotations_forward_refs.toml | 4 +--- .../results/pyright/annotations_typeexpr.toml | 4 +--- .../results/pyright/literals_literalstring.toml | 5 +---- .../results/pyright/narrowing_typeis.toml | 9 +++++++-- .../results/pyright/qualifiers_annotated.toml | 4 +--- conformance/results/pyright/version.toml | 2 +- .../results/pytype/literals_literalstring.toml | 15 +++++++++------ conformance/results/results.html | 2 +- conformance/tests/literals_literalstring.py | 17 +++++++++++------ 14 files changed, 42 insertions(+), 47 deletions(-) diff --git a/conformance/results/mypy/literals_literalstring.toml b/conformance/results/mypy/literals_literalstring.toml index 98ab2a619..b6554e3f6 100644 --- a/conformance/results/mypy/literals_literalstring.toml +++ b/conformance/results/mypy/literals_literalstring.toml @@ -8,18 +8,15 @@ literals_literalstring.py:37: error: Parameter 1 of Literal[...] is invalid [va literals_literalstring.py:43: error: Incompatible types in assignment (expression has type "Literal['two']", variable has type "Literal['']") [assignment] literals_literalstring.py:74: error: Incompatible types in assignment (expression has type "int", variable has type "str") [assignment] literals_literalstring.py:75: error: Incompatible types in assignment (expression has type "bytes", variable has type "str") [assignment] -literals_literalstring.py:142: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap] -literals_literalstring.py:142: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [overload-overlap] -literals_literalstring.py:152: error: Overloaded function signature 3 will never be matched: signature 2's parameter type(s) are the same or broader [misc] -literals_literalstring.py:162: error: Expression is of type "bool", not "str" [assert-type] +literals_literalstring.py:157: error: Overloaded function signature 3 will never be matched: signature 2's parameter type(s) are the same or broader [misc] +literals_literalstring.py:167: error: Expression is of type "B", not "A" [assert-type] """ conformance_automated = "Fail" errors_diff = """ Line 66: Expected 1 errors Line 120: Expected 1 errors Line 134: Expected 1 errors -Line 166: Expected 1 errors -Line 152: Unexpected errors ["literals_literalstring.py:152: error: Overloaded function signature 3 will never be matched: signature 2's parameter type(s) are the same or broader [misc]"] -Line 162: Unexpected errors ['literals_literalstring.py:162: error: Expression is of type "bool", not "str" [assert-type]'] +Line 171: Expected 1 errors +Line 157: Unexpected errors ["literals_literalstring.py:157: error: Overloaded function signature 3 will never be matched: signature 2's parameter type(s) are the same or broader [misc]"] +Line 167: Unexpected errors ['literals_literalstring.py:167: error: Expression is of type "B", not "A" [assert-type]'] """ -ignore_errors = ["overload-overlap"] diff --git a/conformance/results/pyre/literals_literalstring.toml b/conformance/results/pyre/literals_literalstring.toml index f7c601683..c735a90ca 100644 --- a/conformance/results/pyre/literals_literalstring.toml +++ b/conformance/results/pyre/literals_literalstring.toml @@ -9,7 +9,7 @@ literals_literalstring.py:74:4 Incompatible variable type [9]: x3 is declared to literals_literalstring.py:75:4 Incompatible variable type [9]: x4 is declared to have type `typing_extensions.LiteralString` but is used as type `typing_extensions.Literal[b'test']`. literals_literalstring.py:120:21 Incompatible parameter type [6]: In call `literal_identity`, for 1st positional argument, expected `Variable[TLiteral (bound to typing_extensions.LiteralString)]` but got `str`. literals_literalstring.py:134:50 Incompatible parameter type [6]: In call `Container.__init__`, for 1st positional argument, expected `Variable[T (bound to typing_extensions.LiteralString)]` but got `str`. -literals_literalstring.py:166:4 Incompatible variable type [9]: x1 is declared to have type `List[str]` but is used as type `List[typing_extensions.LiteralString]`. +literals_literalstring.py:171:4 Incompatible variable type [9]: x1 is declared to have type `List[str]` but is used as type `List[typing_extensions.LiteralString]`. """ conformance_automated = "Pass" errors_diff = """ diff --git a/conformance/results/pyright/aliases_explicit.toml b/conformance/results/pyright/aliases_explicit.toml index 259a54c81..c52150393 100644 --- a/conformance/results/pyright/aliases_explicit.toml +++ b/conformance/results/pyright/aliases_explicit.toml @@ -37,9 +37,7 @@ aliases_explicit.py:89:22 - error: Invalid expression form for type alias defini aliases_explicit.py:89:22 - error: Expected type expression but received "Literal[1]" (reportGeneralTypeIssues) aliases_explicit.py:90:22 - error: Invalid expression form for type alias definition (reportInvalidTypeForm) aliases_explicit.py:90:22 - error: Binary operator not allowed in type annotation (reportInvalidTypeForm) -aliases_explicit.py:91:22 - error: Expected expression -aliases_explicit.py:91:22 - error: Tuple expression not allowed in type annotation -  Use tuple[T1, ..., Tn] to indicate a tuple type or Union[T1, T2] to indicate a union type (reportInvalidTypeForm) +aliases_explicit.py:91:22 - error: Type annotations cannot use format string literals (f-strings) (reportGeneralTypeIssues) aliases_explicit.py:100:5 - error: Type "list[Unknown]" is already specialized (reportInvalidTypeArguments) aliases_explicit.py:101:6 - error: Object of type "UnionType" is not callable (reportCallIssue) aliases_explicit.py:102:5 - error: Type "list[Unknown]" is already specialized (reportInvalidTypeArguments) diff --git a/conformance/results/pyright/aliases_type_statement.toml b/conformance/results/pyright/aliases_type_statement.toml index 606d17e18..7c3534a53 100644 --- a/conformance/results/pyright/aliases_type_statement.toml +++ b/conformance/results/pyright/aliases_type_statement.toml @@ -34,9 +34,7 @@ aliases_type_statement.py:45:22 - error: Variable not allowed in type expression aliases_type_statement.py:46:23 - error: Expected type expression but received "Literal[True]" (reportGeneralTypeIssues) aliases_type_statement.py:47:23 - error: Expected type expression but received "Literal[1]" (reportGeneralTypeIssues) aliases_type_statement.py:48:23 - error: Binary operator not allowed in type annotation (reportInvalidTypeForm) -aliases_type_statement.py:49:23 - error: Expected expression -aliases_type_statement.py:49:23 - error: Tuple expression not allowed in type annotation -  Use tuple[T1, ..., Tn] to indicate a tuple type or Union[T1, T2] to indicate a union type (reportInvalidTypeForm) +aliases_type_statement.py:49:23 - error: Type annotations cannot use format string literals (f-strings) (reportGeneralTypeIssues) aliases_type_statement.py:52:10 - error: Type alias declaration "BadTypeAlias14" is obscured by a declaration of the same name (reportRedeclaration) aliases_type_statement.py:58:10 - error: A type statement can be used only within a module or class scope (reportGeneralTypeIssues) aliases_type_statement.py:64:23 - error: Type parameter "V" is not included in the type parameter list for "TA1" (reportGeneralTypeIssues) diff --git a/conformance/results/pyright/aliases_typealiastype.toml b/conformance/results/pyright/aliases_typealiastype.toml index 488f49516..94da78ea9 100644 --- a/conformance/results/pyright/aliases_typealiastype.toml +++ b/conformance/results/pyright/aliases_typealiastype.toml @@ -25,9 +25,7 @@ aliases_typealiastype.py:60:42 - error: Variable not allowed in type expression aliases_typealiastype.py:61:42 - error: Expected type expression but received "Literal[True]" (reportGeneralTypeIssues) aliases_typealiastype.py:62:42 - error: Expected type expression but received "Literal[1]" (reportGeneralTypeIssues) aliases_typealiastype.py:63:42 - error: Binary operator not allowed in type annotation (reportInvalidTypeForm) -aliases_typealiastype.py:64:42 - error: Expected expression -aliases_typealiastype.py:64:42 - error: Tuple expression not allowed in type annotation -  Use tuple[T1, ..., Tn] to indicate a tuple type or Union[T1, T2] to indicate a union type (reportInvalidTypeForm) +aliases_typealiastype.py:64:42 - error: Type annotations cannot use format string literals (f-strings) (reportGeneralTypeIssues) """ conformance_automated = "Pass" errors_diff = """ diff --git a/conformance/results/pyright/annotations_forward_refs.toml b/conformance/results/pyright/annotations_forward_refs.toml index 9da88c16a..4ddb40f39 100644 --- a/conformance/results/pyright/annotations_forward_refs.toml +++ b/conformance/results/pyright/annotations_forward_refs.toml @@ -26,9 +26,7 @@ annotations_forward_refs.py:50:11 - error: Expected type expression but received annotations_forward_refs.py:51:11 - error: Expected type expression but received "Literal[1]" (reportGeneralTypeIssues) annotations_forward_refs.py:52:11 - error: Unary operator not allowed in type annotation (reportInvalidTypeForm) annotations_forward_refs.py:53:11 - error: Binary operator not allowed in type annotation (reportInvalidTypeForm) -annotations_forward_refs.py:54:11 - error: Expected expression -annotations_forward_refs.py:54:11 - error: Tuple expression not allowed in type annotation -  Use tuple[T1, ..., Tn] to indicate a tuple type or Union[T1, T2] to indicate a union type (reportInvalidTypeForm) +annotations_forward_refs.py:54:11 - error: Type annotations cannot use format string literals (f-strings) (reportGeneralTypeIssues) annotations_forward_refs.py:55:10 - error: Module cannot be used as a type (reportGeneralTypeIssues) annotations_forward_refs.py:66:26 - error: "ClassB" is not defined (reportUndefinedVariable) annotations_forward_refs.py:80:14 - error: Type of "ClassF" could not be determined because it refers to itself (reportGeneralTypeIssues) diff --git a/conformance/results/pyright/annotations_typeexpr.toml b/conformance/results/pyright/annotations_typeexpr.toml index a80d16b87..1afdc4e4a 100644 --- a/conformance/results/pyright/annotations_typeexpr.toml +++ b/conformance/results/pyright/annotations_typeexpr.toml @@ -22,9 +22,7 @@ annotations_typeexpr.py:97:10 - error: Expected type expression but received "Li annotations_typeexpr.py:98:10 - error: Expected type expression but received "Literal[1]" (reportGeneralTypeIssues) annotations_typeexpr.py:99:10 - error: Unary operator not allowed in type annotation (reportInvalidTypeForm) annotations_typeexpr.py:100:10 - error: Binary operator not allowed in type annotation (reportInvalidTypeForm) -annotations_typeexpr.py:101:10 - error: Expected expression -annotations_typeexpr.py:101:10 - error: Tuple expression not allowed in type annotation -  Use tuple[T1, ..., Tn] to indicate a tuple type or Union[T1, T2] to indicate a union type (reportInvalidTypeForm) +annotations_typeexpr.py:101:10 - error: Type annotations cannot use format string literals (f-strings) (reportGeneralTypeIssues) annotations_typeexpr.py:102:10 - error: Module cannot be used as a type (reportGeneralTypeIssues) """ conformance_automated = "Pass" diff --git a/conformance/results/pyright/literals_literalstring.toml b/conformance/results/pyright/literals_literalstring.toml index 5d507c8ee..4c73a0a0f 100644 --- a/conformance/results/pyright/literals_literalstring.toml +++ b/conformance/results/pyright/literals_literalstring.toml @@ -16,9 +16,7 @@ literals_literalstring.py:120:22 - error: Argument of type "str" cannot be assig literals_literalstring.py:134:51 - error: Argument of type "str" cannot be assigned to parameter "value" of type "T@Container" in function "__init__"   Type "str" cannot be assigned to type "LiteralString"     "str" is incompatible with "LiteralString" (reportArgumentType) -literals_literalstring.py:142:5 - error: Overload 1 for "func8" overlaps overload 2 and returns an incompatible type (reportOverlappingOverload) -literals_literalstring.py:142:5 - error: Overload 1 for "func8" overlaps overload 3 and returns an incompatible type (reportOverlappingOverload) -literals_literalstring.py:166:21 - error: Expression of type "list[LiteralString]" cannot be assigned to declared type "list[str]" +literals_literalstring.py:171:21 - error: Expression of type "list[LiteralString]" cannot be assigned to declared type "list[str]"   "list[LiteralString]" is incompatible with "list[str]"     Type parameter "_T@list" is invariant, but "LiteralString" is not the same as "str"     Consider switching from "list" to "Sequence" which is covariant (reportAssignmentType) @@ -26,4 +24,3 @@ literals_literalstring.py:166:21 - error: Expression of type "list[LiteralString conformance_automated = "Pass" errors_diff = """ """ -ignore_errors = ["reportOverlappingOverload"] diff --git a/conformance/results/pyright/narrowing_typeis.toml b/conformance/results/pyright/narrowing_typeis.toml index 4e2ec8713..3924ee021 100644 --- a/conformance/results/pyright/narrowing_typeis.toml +++ b/conformance/results/pyright/narrowing_typeis.toml @@ -2,9 +2,8 @@ conformant = "Partial" notes = """ Does not reject covariant use of TypeIs. """ -conformance_automated = "Fail" +conformance_automated = "Pass" errors_diff = """ -Line 191: Expected 1 errors """ output = """ narrowing_typeis.py:105:9 - error: User-defined type guard functions and methods must have at least one input parameter (reportGeneralTypeIssues) @@ -29,6 +28,12 @@ narrowing_typeis.py:170:14 - error: Argument of type "(val: object) -> TypeGuard     Function return type "TypeGuard[int]" is incompatible with type "TypeIs[int]"       "TypeGuard[int]" is incompatible with "TypeIs[int]"       "bool" is incompatible with "TypeIs[int]" (reportArgumentType) +narrowing_typeis.py:191:18 - error: Argument of type "(val: object) -> TypeIs[bool]" cannot be assigned to parameter "f" of type "(object) -> TypeIs[int]" in function "takes_int_typeis" +  Type "(val: object) -> TypeIs[bool]" cannot be assigned to type "(object) -> TypeIs[int]" +    Function return type "TypeIs[bool]" is incompatible with type "TypeIs[int]" +      "TypeIs[bool]" is incompatible with "TypeIs[int]" +        Type parameter "T@TypeIs" is invariant, but "bool" is not the same as "int" +      "bool" is incompatible with "TypeIs[int]" (reportArgumentType) narrowing_typeis.py:195:27 - error: Return type of TypeIs ("str") is not consistent with value parameter type ("int") (reportGeneralTypeIssues) narrowing_typeis.py:199:45 - error: Return type of TypeIs ("list[int]") is not consistent with value parameter type ("list[object]") (reportGeneralTypeIssues) """ diff --git a/conformance/results/pyright/qualifiers_annotated.toml b/conformance/results/pyright/qualifiers_annotated.toml index 7731e0068..9a475c9b7 100644 --- a/conformance/results/pyright/qualifiers_annotated.toml +++ b/conformance/results/pyright/qualifiers_annotated.toml @@ -15,9 +15,7 @@ qualifiers_annotated.py:50:17 - error: "var1" is not defined (reportUndefinedVar qualifiers_annotated.py:51:17 - error: Expected type expression but received "Literal[True]" (reportGeneralTypeIssues) qualifiers_annotated.py:52:18 - error: Expected type expression but received "Literal[1]" (reportGeneralTypeIssues) qualifiers_annotated.py:53:18 - error: Binary operator not allowed in type annotation (reportInvalidTypeForm) -qualifiers_annotated.py:54:18 - error: Expected expression -qualifiers_annotated.py:54:18 - error: Tuple expression not allowed in type annotation -  Use tuple[T1, ..., Tn] to indicate a tuple type or Union[T1, T2] to indicate a union type (reportInvalidTypeForm) +qualifiers_annotated.py:54:18 - error: Type annotations cannot use format string literals (f-strings) (reportGeneralTypeIssues) qualifiers_annotated.py:64:8 - error: Expected one type argument and one or more annotations for "Annotated" qualifiers_annotated.py:76:24 - error: Expression of type "type[int]" cannot be assigned to declared type "type[Any]" (reportAssignmentType) qualifiers_annotated.py:77:24 - error: Expression of type "SmallInt" cannot be assigned to declared type "type[Any]" (reportAssignmentType) diff --git a/conformance/results/pyright/version.toml b/conformance/results/pyright/version.toml index 4b1baca77..13b119045 100644 --- a/conformance/results/pyright/version.toml +++ b/conformance/results/pyright/version.toml @@ -1,2 +1,2 @@ -version = "pyright 1.1.357" +version = "pyright 1.1.358" test_duration = 1.6 diff --git a/conformance/results/pytype/literals_literalstring.toml b/conformance/results/pytype/literals_literalstring.toml index 489e55fd8..32d16477f 100644 --- a/conformance/results/pytype/literals_literalstring.toml +++ b/conformance/results/pytype/literals_literalstring.toml @@ -10,19 +10,22 @@ File "literals_literalstring.py", line 37, in : Invalid type annotation File "literals_literalstring.py", line 43, in func1: Type annotation for x2 does not match type of assignment [annotation-type-mismatch] File "literals_literalstring.py", line 74, in func2: Type annotation for x3 does not match type of assignment [annotation-type-mismatch] File "literals_literalstring.py", line 75, in func2: Type annotation for x4 does not match type of assignment [annotation-type-mismatch] -File "literals_literalstring.py", line 157, in func8: bad return type [bad-return-type] +File "literals_literalstring.py", line 162, in func8: bad return type [bad-return-type] Called from (traceback): - line 160, in current file -File "literals_literalstring.py", line 162, in : bool [assert-type] + line 166, in current file +File "literals_literalstring.py", line 162, in func8: bad return type [bad-return-type] +Called from (traceback): + line 165, in current file +File "literals_literalstring.py", line 167, in : B [assert-type] """ conformance_automated = "Fail" errors_diff = """ Line 66: Expected 1 errors Line 120: Expected 1 errors Line 134: Expected 1 errors -Line 166: Expected 1 errors +Line 171: Expected 1 errors Line 8: Unexpected errors ['File "literals_literalstring.py", line 8, in : typing.LiteralString not supported yet [not-supported-yet]'] Line 24: Unexpected errors ['File "literals_literalstring.py", line 24, in my_function: bad return type [bad-return-type]'] -Line 157: Unexpected errors ['File "literals_literalstring.py", line 157, in func8: bad return type [bad-return-type]'] -Line 162: Unexpected errors ['File "literals_literalstring.py", line 162, in : bool [assert-type]'] +Line 162: Unexpected errors ['File "literals_literalstring.py", line 162, in func8: bad return type [bad-return-type]', 'File "literals_literalstring.py", line 162, in func8: bad return type [bad-return-type]'] +Line 167: Unexpected errors ['File "literals_literalstring.py", line 167, in : B [assert-type]'] """ diff --git a/conformance/results/results.html b/conformance/results/results.html index 9eaa2a212..2a0bf7168 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -161,7 +161,7 @@

Python Type System Conformance Test Results

mypy 1.9.0
2.2sec
-
pyright 1.1.357
+
pyright 1.1.358
1.6sec
pyre 0.9.19
diff --git a/conformance/tests/literals_literalstring.py b/conformance/tests/literals_literalstring.py index 2c9754b46..25461dd11 100644 --- a/conformance/tests/literals_literalstring.py +++ b/conformance/tests/literals_literalstring.py @@ -138,18 +138,23 @@ def func7(s: str): xs: list[LiteralString] = ["foo", "bar", "baz"] +class A: pass +class B(A): pass +class C(B): pass + + @overload -def func8(x: Literal["foo"]) -> int: +def func8(x: Literal["foo"]) -> C: ... @overload -def func8(x: LiteralString) -> bool: +def func8(x: LiteralString) -> B: ... @overload -def func8(x: str) -> str: +def func8(x: str) -> A: ... @@ -157,9 +162,9 @@ def func8(x: Any) -> Any: ... -assert_type(func8("foo"), int) # First overload -assert_type(func8("bar"), bool) # Second overload -assert_type(func8(str(1)), str) # Third overload +assert_type(func8("foo"), C) # First overload +assert_type(func8("bar"), B) # Second overload +assert_type(func8(str(1)), A) # Third overload def func9(val: list[LiteralString]):