-
Notifications
You must be signed in to change notification settings - Fork 200
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
🐛 FIX: aiida/repository typing #4920
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7ce46d7
🐛 FIX: aiida/repository typing
chrisjsewell 00121d0
Merge branch 'develop' into fix-repo-typing
chrisjsewell 3af25c0
Delete cmd_repository.py
chrisjsewell 8f24460
remove unused imports
chrisjsewell 885ec03
Update nitpick-exceptions
chrisjsewell 79533d0
create check_byte_stream
chrisjsewell ef7176b
Update abstract.py
chrisjsewell 6349f17
Update abstract.py
chrisjsewell ea43455
remove conditional and _backend class attribute
chrisjsewell 3e62aeb
fix pre-commit
chrisjsewell f18da24
Update test_abstract.py
chrisjsewell 17b5544
use _put_object_from_filelike
chrisjsewell bb7e107
Update repository.py
chrisjsewell d792085
add string tests
chrisjsewell 6daadeb
fix yapf
chrisjsewell f259753
Merge branch 'develop' into fix-repo-typing
chrisjsewell b8428b2
improve test
chrisjsewell 1ee62d2
Merge branch 'develop' into fix-repo-typing
chrisjsewell 7aa3d05
fixes
chrisjsewell 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -44,7 +44,7 @@ def is_initialised(self) -> bool: | |
"""Return whether the repository has been initialised.""" | ||
|
||
@abc.abstractmethod | ||
def erase(self): | ||
def erase(self) -> None: | ||
"""Delete the repository itself and all its contents. | ||
|
||
.. note:: This should not merely delete the contents of the repository but any resources it created. For | ||
|
@@ -53,17 +53,23 @@ def erase(self): | |
""" | ||
|
||
@staticmethod | ||
def is_readable_byte_stream(handle): | ||
def is_readable_byte_stream(handle) -> bool: | ||
return hasattr(handle, 'read') and hasattr(handle, 'mode') and 'b' in handle.mode | ||
|
||
def put_object_from_filelike(self, handle: io.BufferedIOBase) -> str: | ||
def put_object_from_filelike(self, handle: typing.BinaryIO) -> str: | ||
"""Store the byte contents of a file in the repository. | ||
|
||
:param handle: filelike object with the byte content to be stored. | ||
:return: the generated fully qualified identifier for the object within the repository. | ||
:raises TypeError: if the handle is not a byte stream. | ||
""" | ||
if not isinstance(handle, io.BytesIO) and not self.is_readable_byte_stream(handle): | ||
raise TypeError(f'handle does not seem to be a byte stream: {type(handle)}.') | ||
return self._put_object_from_filelike(handle) | ||
|
||
@abc.abstractmethod | ||
def _put_object_from_filelike(self, handle: typing.BinaryIO) -> str: | ||
pass | ||
|
||
def put_object_from_file(self, filepath: typing.Union[str, pathlib.Path]) -> str: | ||
"""Store a new object with contents of the file located at `filepath` on this file system. | ||
|
@@ -84,7 +90,7 @@ def has_object(self, key: str) -> bool: | |
""" | ||
|
||
@contextlib.contextmanager | ||
def open(self, key: str) -> io.BufferedIOBase: | ||
def open(self, key: str) -> typing.Iterator[typing.BinaryIO]: # type: ignore[return] | ||
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. hmmm, these abstract methods, that you also need to call |
||
"""Open a file handle to an object stored under the given key. | ||
|
||
.. note:: this should only be used to open a handle to read an existing file. To write a new file use the method | ||
|
This file contains 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 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
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.
mypy didn't like this, and it feels like it goes a bit against the concept of an abstract method, so I moved it to a separate method. But its not a deal breaker
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.
I guess the best way to do this technically is something like:
then the concrete methods do not have to "remember" to call
super()
or any other initial codeThere 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.
done