-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
list.__add__ isn't permissive enough #8292
Comments
It seems reasonable to change it to: _T = TypeVar("_T")
_S = TypeVar("_S")
class list(MutableSequence[_T]):
def __add__(self, __x: list[_S]) -> list[_T | _S]:... We already do a similar thing with Line 1051 in 82745be
|
This is trickier than it seems, see #3183 for the last attempt. |
I'll try again. The last attempt was done mostly before |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.The text was updated successfully, but these errors were encountered: