-
Notifications
You must be signed in to change notification settings - Fork 232
Strict typing for aiida.repository module #7049
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,15 @@ | |
| import hashlib | ||
| import io | ||
| import pathlib | ||
| from typing import BinaryIO, Iterable, Iterator, List, Optional, Tuple, Union | ||
| from collections.abc import Iterable, Iterator | ||
| from typing import Any, BinaryIO, List, Optional, Tuple, Union | ||
|
|
||
| from aiida.common.hashing import chunked_file_hash | ||
|
|
||
| __all__ = ('AbstractRepositoryBackend',) | ||
|
|
||
| InfoDictType = dict[str, Union[int, str, dict[str, int], dict[str, float]]] | ||
|
|
||
|
|
||
| class AbstractRepositoryBackend(metaclass=abc.ABCMeta): | ||
| """Class that defines the abstract interface for an object repository. | ||
|
|
@@ -44,7 +47,7 @@ def key_format(self) -> Optional[str]: | |
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def initialise(self, **kwargs) -> None: | ||
| def initialise(self, **kwargs: Any) -> None: | ||
| """Initialise the repository if it hasn't already been initialised. | ||
|
|
||
| :param kwargs: parameters for the initialisation. | ||
|
|
@@ -65,7 +68,7 @@ def erase(self) -> None: | |
| """ | ||
|
|
||
| @staticmethod | ||
| def is_readable_byte_stream(handle) -> bool: | ||
| def is_readable_byte_stream(handle: Any) -> bool: | ||
| return hasattr(handle, 'read') and hasattr(handle, 'mode') and 'b' in handle.mode | ||
|
|
||
| def put_object_from_filelike(self, handle: BinaryIO) -> str: | ||
|
|
@@ -120,7 +123,7 @@ def list_objects(self) -> Iterable[str]: | |
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def get_info(self, detailed: bool = False, **kwargs) -> dict: | ||
| def get_info(self, detailed: bool = False) -> InfoDictType: | ||
| """Returns relevant information about the content of the repository. | ||
|
|
||
| :param detailed: | ||
|
|
@@ -129,19 +132,6 @@ def get_info(self, detailed: bool = False, **kwargs) -> dict: | |
| :return: a dictionary with the information. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def maintain(self, dry_run: bool = False, live: bool = True, **kwargs) -> None: | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was causing liskov principle violations in the subclasses. Ultimately, the "maintain" operation will be specialized for each different backend to probably doesn't make sense to have it here. |
||
| """Performs maintenance operations. | ||
|
|
||
| :param dry_run: | ||
| flag to only print the actions that would be taken without actually executing them. | ||
|
|
||
| :param live: | ||
| flag to indicate to the backend whether AiiDA is live or not (i.e. if the profile of the | ||
| backend is currently being used/accessed). The backend is expected then to only allow (and | ||
| thus set by default) the operations that are safe to perform in this state. | ||
| """ | ||
|
|
||
| @contextlib.contextmanager | ||
| def open(self, key: str) -> Iterator[BinaryIO]: # type: ignore[return] | ||
| """Open a file handle to an object stored under the given key. | ||
|
|
@@ -168,7 +158,7 @@ def get_object_content(self, key: str) -> bytes: | |
| return handle.read() | ||
|
|
||
| @abc.abstractmethod | ||
| def iter_object_streams(self, keys: List[str]) -> Iterator[Tuple[str, BinaryIO]]: | ||
| def iter_object_streams(self, keys: Iterable[str]) -> Iterator[Tuple[str, BinaryIO]]: | ||
| """Return an iterator over the (read-only) byte streams of objects identified by key. | ||
|
|
||
| .. note:: handles should only be read within the context of this iterator. | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have a better type than this 😅