Closed
Description
Works at runtime, doesn't type check:
class Foo:
def asd(self) -> int:
return 1
class Bar:
def asd(self) -> int:
return 2
combined = [Foo()] + [Bar()]
for item in combined:
print(item.asd())
I would expect [Foo()] + [Bar()]
to produce list[Foo | Bar]
.
Converting to tuples works as expected:
combined = tuple([Foo()]) + tuple([Bar()])
But invariance problems don't apply here, because we're constructing a new list that doesn't refer to the old lists in any way.
There has previously been discussion about how mypy doesn't understand [Foo(), Bar()]
, but this is slightly different: I'm adding lists, not mixing types within different elements of a single list literal.
Metadata
Metadata
Assignees
Labels
No labels