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.
Activity
AlexWaygood commented on Jul 13, 2022
It seems reasonable to change it to:
We already do a similar thing with dict.__or__:
typeshed/stdlib/builtins.pyi
Line 1051 in 82745be
JelleZijlstra commented on Jul 13, 2022
This is trickier than it seems, see #3183 for the last attempt.
Akuli commented on Jul 13, 2022
I'll try again. The last attempt was done mostly before mypy_primer was a thing, so this time we should at least know if something breaks.