Implement array.array as a MutableSequence#1649
Conversation
It also improves the type checking of contained values. Some methods were removed because they are implemented by a base class (i.e., *__iter__()*, *__str__()*, and *__contains__()*). *__hash__()* was removed because arrays are unhashable types.
| @overload | ||
| def __getitem__(self, s: slice) -> 'array[_T]': ... | ||
|
|
||
| @overload # type: ignore # Overrides MutableSequence |
There was a problem hiding this comment.
MutableSequence, the supertype, defines __setitem__() like this:
@overload
def __setitem__(self, i: int, o: _T) -> None: ...
@overload
def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ...But array requires an array instance. The # type: ignore comment quiets the Signature of "__setitem__" incompatible with supertype "MutableSequence" error emitted by mypy, but pytype doesn't emit an error when the type comment is omitted nor does it like the type comment.
Any thoughts on how to handle this one?
There was a problem hiding this comment.
I can't think of anything else here than lying about the signature and putting Iterable[_T]. We can put a TODO to fix it when pytype's parser becomes more permissive (cc @matthiaskramm).
|
pytype has its own array.pyi, so it's fine if we just blacklist this file, in tests/pytype_blacklist.txt, with a comment that we had to because pytype doesn't yet support "# type: ignore" after decorators. (That's what is breaking, right?) |
|
Sounds good, can you implement Matthias's suggestion? |
Due to pytype's lack of support for '# type: ignore' annotations after decorators.
|
Hey, if you also copy this into stdlib/2 (with very minor changes) then it will fix #1608. |
|
@gvanrossum I submitted pull request #1670 to merge array stubs. |
It also improves the type checking of contained values. Some methods
were removed because they are implemented by a base class (i.e.,
iter(), str(), and contains()). hash() was
removed because arrays are unhashable types.