Skip to content
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

Implement array.array as a MutableSequence #1649

Merged
merged 3 commits into from
Oct 9, 2017

Conversation

hashstat
Copy link
Contributor

@hashstat hashstat commented Oct 5, 2017

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.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@matthiaskramm
Copy link
Contributor

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?)

@JelleZijlstra
Copy link
Member

Sounds good, can you implement Matthias's suggestion?

Due to pytype's lack of support for '# type: ignore' annotations after
decorators.
@matthiaskramm matthiaskramm merged commit 2947374 into python:master Oct 9, 2017
@gvanrossum
Copy link
Member

Hey, if you also copy this into stdlib/2 (with very minor changes) then it will fix #1608.

@hashstat
Copy link
Contributor Author

@gvanrossum I submitted pull request #1670 to merge array stubs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants