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

ENH: Add annotations for np.memmap #19979

Merged
merged 2 commits into from
Sep 28, 2021
Merged

ENH: Add annotations for np.memmap #19979

merged 2 commits into from
Sep 28, 2021

Conversation

BvB93
Copy link
Member

@BvB93 BvB93 commented Sep 27, 2021

This PR adds annotations for the np.memmap class.

Comment on lines +640 to +649
# NOTE: `seek`, `write` and `flush` are technically only required
# for `readwrite`/`write` modes
class _MemMapIOProtocol(Protocol):
def flush(self) -> object: ...
def fileno(self) -> SupportsIndex: ...
def tell(self) -> int: ...
def seek(self, offset: int, whence: int, /) -> object: ...
def write(self, s: bytes, /) -> object: ...
@property
def read(self) -> object: ...
Copy link
Member Author

Choose a reason for hiding this comment

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

Interestingly memmap.__new__ uses the read attribute for identifying file-like objects, but then never actually calls it.

Comment on lines +1 to +5
from typing import List

from numpy import memmap as memmap

__all__: List[str]
Copy link
Member Author

Choose a reason for hiding this comment

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

It's not strictly necessary to add stub file here, but it does make it easier to find the memmap annotations if someone is looking for them.

@charris charris merged commit 1d5b2b8 into numpy:main Sep 28, 2021
@charris
Copy link
Member

charris commented Sep 28, 2021

Thanks Bas.

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

Successfully merging this pull request may close these issues.

None yet

2 participants