← 返回首页
Implement array.array as a MutableSequence by hashstat · Pull Request #1649 · python/typeshed · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

Implement array.array as a MutableSequence#1649

Merged
matthiaskramm merged 3 commits into
python:masterfrom
hashstat:array-as-a-sequence
Oct 9, 2017
Merged

Implement array.array as a MutableSequence#1649
matthiaskramm merged 3 commits into
python:masterfrom
hashstat:array-as-a-sequence

Conversation

hashstat commented Oct 5, 2017

Copy link
Copy Markdown
Contributor

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.
Comment thread stdlib/3/array.pyi
@overload
def __getitem__(self, s: slice) -> 'array[_T]': ...

@overload # type: ignore # Overrides MutableSequence

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide 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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide 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).

Copy link
Copy Markdown
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?)

Copy link
Copy Markdown
Member

Sounds good, can you implement Matthias's suggestion?

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

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor Author

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

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Footer

© 2026 GitHub, Inc.