Skip to content

Commit

Permalink
Run mypy on orm/{comments,computer}.py
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhollas committed Jan 15, 2025
1 parent b432611 commit a368f6b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
3 changes: 0 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ repos:
src/aiida/manage/external/rmq/launcher.py|
src/aiida/manage/tests/main.py|
src/aiida/manage/tests/pytest_fixtures.py|
src/aiida/orm/comments.py|
src/aiida/orm/computers.py|
src/aiida/orm/implementation/storage_backend.py|
src/aiida/orm/nodes/comments.py|
src/aiida/orm/nodes/data/array/bands.py|
src/aiida/orm/nodes/data/array/trajectory.py|
src/aiida/orm/nodes/data/cif.py|
Expand Down
7 changes: 4 additions & 3 deletions src/aiida/orm/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

if TYPE_CHECKING:
from aiida.orm import Node, User
from aiida.orm.implementation import StorageBackend
from aiida.orm.implementation import BackendComment, BackendNode, StorageBackend # noqa: F401

__all__ = ('Comment',)

Expand Down Expand Up @@ -146,15 +146,16 @@ def set_mtime(self, value: datetime) -> None:
return self._backend_entity.set_mtime(value)

@property
def node(self) -> 'Node':
def node(self) -> 'BackendNode':
return self._backend_entity.node

@property
def user(self) -> 'User':
return entities.from_backend_entity(users.User, self._backend_entity.user)

def set_user(self, value: 'User') -> None:
self._backend_entity.user = value.backend_entity
# ignoring mypy error: Property "user" defined in "BackendComment" is read-only
self._backend_entity.user = value.backend_entity # type: ignore[misc]

@property
def content(self) -> str:
Expand Down
12 changes: 6 additions & 6 deletions src/aiida/orm/computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -54,7 +54,7 @@ def get_or_create(self, label: Optional[str] = None, **kwargs) -> Tuple[bool, 'C

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]

def delete(self, pk: int) -> None:
"""Delete the computer with the given id"""
Expand Down Expand Up @@ -224,7 +224,7 @@ def _mpirun_command_validator(self, mpirun_cmd: Union[List[str], Tuple[str, ...]
"""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]
raise exceptions.ValidationError('the mpirun_command must be a list of strings')

try:
Expand Down Expand Up @@ -278,7 +278,7 @@ def _default_mpiprocs_per_machine_validator(cls, def_cpus_per_machine: Optional[
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.'
Expand All @@ -290,7 +290,7 @@ def default_memory_per_machine_validator(cls, def_memory_per_machine: Optional[i
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}'
)
Expand Down Expand Up @@ -487,7 +487,7 @@ def set_mpirun_command(self, val: Union[List[str], Tuple[str, ...]]) -> None:
"""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)

Expand Down
2 changes: 1 addition & 1 deletion src/aiida/transports/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Transport(abc.ABC):
"""Abstract class for a generic transport (ssh, local, ...) contains the set of minimal methods."""

# This will be used for ``Computer.get_minimum_job_poll_interval``
DEFAULT_MINIMUM_JOB_POLL_INTERVAL = 10
DEFAULT_MINIMUM_JOB_POLL_INTERVAL = 10.0

# This is used as a global default in case subclasses don't redefine this,
# but this should be redefined in plugins where appropriate
Expand Down

0 comments on commit a368f6b

Please sign in to comment.