-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix Incompatible return value type
error message for long tuple with Union
and non-Union
type mismatch
#18881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
a58a971
220a2f4
11a6c13
9109962
57177bf
e36a0c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1665,6 +1665,45 @@ a.f = a.f # E: Property "f" defined in "A" is read-only | |
a.f.x # E: "int" has no attribute "x" | ||
[builtins fixtures/property.pyi] | ||
|
||
[case testPropertyWithTupleUnionAndNonUnionMismatchReturnValueType] | ||
from typing import Tuple, Union | ||
class A: | ||
a: str | ||
b: str | ||
c: str | ||
d: str | ||
e: str | ||
f: str | ||
g: Union[str, int] | ||
h: Union[str, float] | ||
i: Union[str, None] | ||
j: Union[str, None] | ||
k: Union[str, None] | ||
l: Union[str, None] | ||
|
||
@property | ||
def x(self) -> Tuple[str, str, str, str, str, str, str, str, str, str, str, str]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a testcase with the opposite direction (annotated with tuple of unions, returns tuple of props) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sterliakov Just to make sure I understand, you would like me to test this configuration ? class A:
a: str
b: str
c: str
d: str
e: str
f: str
g: str
h: str
i: str
j: str
k: str
l: str
@property
def x(self) -> Tuple[Union[str, int], Union[str, float], Union[str, None], Union[str, None], Union[str, None], Union[str, None], str, str, str, str, str, str]:
return (
self.a,
self.b,
self.c,
self.d,
self.e,
self.f,
self.g,
self.h,
self.i,
self.j,
self.k,
self.l,
) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd love to see a test where the expected return type is wider than the actual return type, but the changed method is still triggered. In your example all items are assignable, so that method won't fire. Something like class A:
a: str
b: str
c: str
d: str
e: str
f: str
g: str
h: str
i: str
j: str
k: str
l: str
@property
def x(self) -> Tuple[Union[str, int], Union[str, float], int, Union[str, None], Union[str, None], Union[str, None], str, str, str, str, str, str]:
return (
self.a,
self.b,
self.c,
self.d,
self.e,
self.f,
self.g,
self.h,
self.i,
self.j,
self.k,
self.l,
) I adjusted the third union item to not be assignable, so that the comparator should be triggered (please check that it actually is). And why is a: str
b: str
c: str
d: str
e: str
f: str
g: str
h: str
i: str
j: str
k: str
l: str
x: Tuple[
Union[str, int], Union[str, float], int, Union[str, None], Union[str, None],
Union[str, None], str, str, str, str,
str, str,
] = (
a, b, c, d, e,
f, g, h, i, j,
k, l,
) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And a nit: please move this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the clarification and the provided example.
It indeed triggers to relevant error. I also a
Beside beging the configuration where I first encountered the error message issue, your suggestion triggers an |
||
return ( | ||
self.a, | ||
self.b, | ||
self.c, | ||
self.d, | ||
self.e, | ||
self.f, | ||
self.g, | ||
self.h, | ||
self.i, | ||
self.j, | ||
self.k, | ||
self.l, | ||
) | ||
[out] | ||
main:18: error: Incompatible return value type (6 tuple items are incompatible; 3 items are omitted) | ||
main:18: note: Expression tuple item 6 has type "Union[str, int]"; "str" expected; | ||
main:18: note: Expression tuple item 7 has type "Union[str, float]"; "str" expected; | ||
main:18: note: Expression tuple item 8 has type "Optional[str]"; "str" expected; | ||
[builtins fixtures/property.pyi] | ||
|
||
-- Descriptors | ||
-- ----------- | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.