Works at runtime, doesn't type check:
classFoo:
defasd(self) ->int:
return1classBar:
defasd(self) ->int:
return2combined= [Foo()] + [Bar()]
foritemincombined:
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.
Works at runtime, doesn't type check:
I would expect
[Foo()] + [Bar()]to producelist[Foo | Bar].Converting to tuples works as expected:
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.