Skip to content

Commit 220a2f4

Browse files
committed
test: union and non-union type mismatch case
1 parent a58a971 commit 220a2f4

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test-data/unit/check-classes.test

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,45 @@ a.f = a.f # E: Property "f" defined in "A" is read-only
16651665
a.f.x # E: "int" has no attribute "x"
16661666
[builtins fixtures/property.pyi]
16671667

1668+
[case testPropertyWithTupleUnionAndNonUnionMismatchReturnValueType]
1669+
from typing import Tuple, Union
1670+
class A:
1671+
a: str
1672+
b: str
1673+
c: str
1674+
d: str
1675+
e: str
1676+
f: str
1677+
g: Union[str, int]
1678+
h: Union[str, float]
1679+
i: Union[str, None]
1680+
j: Union[str, None]
1681+
k: Union[str, None]
1682+
l: Union[str, None]
1683+
1684+
@property
1685+
def x(self) -> Tuple[str, str, str, str, str, str, str, str, str, str, str, str]:
1686+
return (
1687+
self.a,
1688+
self.b,
1689+
self.c,
1690+
self.d,
1691+
self.e,
1692+
self.f,
1693+
self.g,
1694+
self.h,
1695+
self.i,
1696+
self.j,
1697+
self.k,
1698+
self.l,
1699+
)
1700+
[out]
1701+
main:18: error: Incompatible return value type (6 tuple items are incompatible; 3 items are omitted)
1702+
main:18: note: Expression tuple item 6 has type "Union[str, int]"; "str" expected;
1703+
main:18: note: Expression tuple item 7 has type "Union[str, float]"; "str" expected;
1704+
main:18: note: Expression tuple item 8 has type "Optional[str]"; "str" expected;
1705+
[builtins fixtures/property.pyi]
1706+
16681707
-- Descriptors
16691708
-- -----------
16701709

0 commit comments

Comments
 (0)