-
Notifications
You must be signed in to change notification settings - Fork 192
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
Run typing on orm/{comments,computers}.py and orm/implementation/storage_backend.py #6704
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
|
||
if TYPE_CHECKING: | ||
from aiida.orm import AuthInfo, User | ||
from aiida.orm.implementation import StorageBackend | ||
from aiida.orm.implementation import BackendComputer, StorageBackend # noqa: F401 | ||
from aiida.schedulers import Scheduler | ||
from aiida.transports import Transport | ||
|
||
|
@@ -54,7 +54,7 @@ | |
|
||
def list_labels(self) -> List[str]: | ||
"""Return a list with all the labels of the computers in the DB.""" | ||
return self._backend.computers.list_names() | ||
return self._backend.computers.list_names() # type: ignore[attr-defined] | ||
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. I am not sure why mypy complains here |
||
|
||
def delete(self, pk: int) -> None: | ||
"""Delete the computer with the given id""" | ||
|
@@ -224,7 +224,7 @@ | |
"""Validates the mpirun_command variable. MUST be called after properly | ||
checking for a valid scheduler. | ||
""" | ||
if not isinstance(mpirun_cmd, (tuple, list)) or not all(isinstance(i, str) for i in mpirun_cmd): | ||
if not isinstance(mpirun_cmd, (tuple, list)) or not all(isinstance(i, str) for i in mpirun_cmd): # type: ignore[redundant-expr] | ||
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. Mypy complains that the isinstance check should be always true since the mpirun_cmd is typed at list or tuple, but we obviously want to preserve the runtime check since we don't control all the callers. 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. Or I think the better change would be we move the mpirun_cmd runtime check when set up the computer? But it seems out the scope of this PR. |
||
raise exceptions.ValidationError('the mpirun_command must be a list of strings') | ||
|
||
try: | ||
|
@@ -278,7 +278,7 @@ | |
if def_cpus_per_machine is None: | ||
return | ||
|
||
if not isinstance(def_cpus_per_machine, int) or def_cpus_per_machine <= 0: | ||
if not isinstance(def_cpus_per_machine, int) or def_cpus_per_machine <= 0: # type: ignore[redundant-expr] | ||
raise exceptions.ValidationError( | ||
'Invalid value for default_mpiprocs_per_machine, must be a positive integer, or an empty string if you ' | ||
'do not want to provide a default value.' | ||
|
@@ -290,7 +290,7 @@ | |
if def_memory_per_machine is None: | ||
return | ||
|
||
if not isinstance(def_memory_per_machine, int) or def_memory_per_machine <= 0: | ||
if not isinstance(def_memory_per_machine, int) or def_memory_per_machine <= 0: # type: ignore[redundant-expr] | ||
raise exceptions.ValidationError( | ||
f'Invalid value for def_memory_per_machine, must be a positive int, got: {def_memory_per_machine}' | ||
) | ||
|
@@ -487,7 +487,7 @@ | |
"""Set the mpirun command. It must be a list of strings (you can use | ||
string.split() if you have a single, space-separated string). | ||
""" | ||
if not isinstance(val, (tuple, list)) or not all(isinstance(i, str) for i in val): | ||
if not isinstance(val, (tuple, list)) or not all(isinstance(i, str) for i in val): # type: ignore[redundant-expr] | ||
raise TypeError('the mpirun_command must be a list of strings') | ||
self.set_property('mpirun_command', val) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -456,7 +456,7 @@ def get_orm_entities(self, detailed: bool = False) -> dict: | |
""" | ||
from aiida.orm import Comment, Computer, Group, Log, Node, QueryBuilder, User | ||
|
||
data = {} | ||
data: dict[str, Any] = {} | ||
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. Without this change I get these errors:
I don't know if there is a better solution. 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. I'd do the same. |
||
|
||
query_user = QueryBuilder(self).append(User, project=['email']) | ||
data['Users'] = {'count': query_user.count()} | ||
|
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.
If I don't import
BackendComment
I get the following error:From this code:
aiida-core/src/aiida/orm/comments.py
Line 63 in 199a027
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.
The
noqa
is needed because ruff complains about an unused import. I think this is a bug in ruff, I'll file an issue.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.
In seems a bit strange the type in the square of Entity is mixed, did you try
entities.Entity['BackendComment', 'CommentCollection']
? I remember my basedpyright gave something that can not use string and class for typing at same time. But doesn't matter, let's use noqa for the moment.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.
Just look at the type annotation, I am wondering if it can be just have a generic type to hold both
backendComment
andCommentCollection
?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.
But is it even technically a type annotation? I don't know how the
entities.Entity
is even supposed to work, since this is somehow specifying the parent class forComment
.I don't think I'd want to touch this in this PR in any case tbh.
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.
Fair, this typing annotation is quite confuse. But let's keep as it is. We can come back and check all
noqa
. I'd say, the complex typing usually come from improper design, but it requires way more effort to touch some core parts of storage.