You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that both MyList1 and MyList2 are list subclasses, and all I'm attempting to do is initialize instances and use += (.__iadd__) and .extend to extend them.
Running the above code results in the following mostly unsurprising output in Python 3.6.6:
Let's ignore the disparate type representations in Python 3.6.6 -- my concern is that mypy complains that the in-place extensions using __iadd__ result in invalid result types in both cases and both versions:
test.py:5: error: Result type of + incompatible in assignment
test.py:11: error: Result type of + incompatible in assignment
My first reaction was that I am doing something wrong. However, after scouring the internet, this problem doesn't appear to be an instance of one of the common typing pitfalls. The mypy result simply does not match the actual runtime types produced by CPython, which suggests to me that the mypy type model for list.__iadd__ is incorrect and resulting in a spurious error.
I'm reporting this potential bug here, rather than in the typeshed repository, since this deals with a built-in type, assumptions about the core type model, and not the standard library. Apologies in advance if I'm wrong about any of the above.
The text was updated successfully, but these errors were encountered:
This is actually a typeshed issue, mypy uses typeshed even for builtin types. You can try to propose a more precise signature for __iadd__() using self-types (currently it returns List). But be careful with #2354.
list.__iadd__
type model appears to be wrongExamples:
Note that both
MyList1
andMyList2
arelist
subclasses, and all I'm attempting to do is initialize instances and use+= (.__iadd__)
and.extend
to extend them.Running the above code results in the following mostly unsurprising output in Python 3.6.6:
and in Python 3.7.1:
Let's ignore the disparate type representations in Python 3.6.6 -- my concern is that
mypy
complains that the in-place extensions using__iadd__
result in invalid result types in both cases and both versions:My first reaction was that I am doing something wrong. However, after scouring the internet, this problem doesn't appear to be an instance of one of the common typing pitfalls. The
mypy
result simply does not match the actual runtime types produced by CPython, which suggests to me that themypy
type model forlist.__iadd__
is incorrect and resulting in a spurious error.I'm reporting this potential bug here, rather than in the
typeshed
repository, since this deals with a built-in type, assumptions about the core type model, and not the standard library. Apologies in advance if I'm wrong about any of the above.The text was updated successfully, but these errors were encountered: