-
Notifications
You must be signed in to change notification settings - Fork 189
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
CalcJobResultManager
: fix bug that broke tab completion
#4187
Merged
sphuber
merged 3 commits into
aiidateam:develop
from
sphuber:fix/4184/calcjob-res-tabcomplete
Jun 23, 2020
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ def get_results(self): | |
|
||
def __dir__(self): | ||
"""Add the keys of the results dictionary such that they can be autocompleted.""" | ||
return sorted(set(list(dir(type(self))) + list(self.get_results().keys()))) | ||
return sorted(list(self.get_results().keys())) | ||
|
||
def __iter__(self): | ||
"""Return an iterator over the keys of the result dictionary.""" | ||
|
@@ -93,21 +93,25 @@ def __getattr__(self, name): | |
|
||
:param name: name of the result return | ||
:return: value of the attribute | ||
:raises AttributeError: if the results dictionary does not contain an attribute with the given name | ||
:raises AttributeError: if the results node cannot be retrieved or it does not contain the `name` attribute | ||
""" | ||
try: | ||
return self.get_results()[name] | ||
except AttributeError: | ||
except ValueError as exception: | ||
raise AttributeError from exception | ||
except KeyError: | ||
raise AttributeError("Default result node<{}> does not contain key '{}'".format(self._result_node.pk, name)) | ||
|
||
def __getitem__(self, name): | ||
"""Return an attribute from the results dictionary. | ||
|
||
:param name: name of the result return | ||
:return: value of the attribute | ||
:raises AttributeError: if the results dictionary does not contain an attribute with the given name | ||
:raises KeyError: if the results node cannot be retrieved or it does not contain the `name` attribute | ||
""" | ||
try: | ||
return self.get_results()[name] | ||
except AttributeError: | ||
raise AttributeError("Default result node<{}> does not contain key '{}'".format(self._result_node.pk, name)) | ||
except ValueError as exception: | ||
raise KeyError from exception | ||
except KeyError: | ||
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. Also here |
||
raise KeyError("Default result node<{}> does not contain key '{}'".format(self._result_node.pk, name)) |
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
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.
I think we need to guard also for any exception that can happen in
get_results
, both here and below.I found at least two possibilities, both a
ValueError
:I am not sure if there is still some case if an AttributeError can still be raised.
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.
For tests, in the first case I just created an unstored
CalcJobNode()
; in the second one, a calculation that excepted and hand no output node.