Skip to content

Commit

Permalink
src/aiida/manage/configuration/profile.py out of mypy exclude list
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Nov 15, 2024
1 parent 5ed4950 commit 1b26044
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ repos:
src/aiida/engine/processes/ports.py|
src/aiida/manage/configuration/__init__.py|
src/aiida/manage/configuration/config.py|
src/aiida/manage/configuration/profile.py|
src/aiida/manage/external/rmq/launcher.py|
src/aiida/manage/tests/main.py|
src/aiida/manage/tests/pytest_fixtures.py|
Expand Down
4 changes: 3 additions & 1 deletion src/aiida/common/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def isidentifier(identifier):
return identifier.isidentifier() and not keyword.iskeyword(identifier)


def type_check(what, of_type, msg=None, allow_none=False):
def type_check(
what: object, of_type, msg: str | None = None, allow_none: bool = False
) -> object | None:
"""Verify that object 'what' is of type 'of_type' and if not the case, raise a TypeError.
:param what: the object to check
Expand Down
28 changes: 12 additions & 16 deletions src/aiida/manage/configuration/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pathlib
from collections import abc
from copy import deepcopy
from typing import TYPE_CHECKING, Any, Dict, Literal, Mapping, Optional, Type
from typing import TYPE_CHECKING, Any, Literal, cast

from aiida.common import exceptions
from aiida.common.lang import type_check
Expand Down Expand Up @@ -43,13 +43,13 @@ class Profile:
KEY_TEST_PROFILE: str = 'test_profile'

# keys that are expected to be in the parsed configuration
REQUIRED_KEYS: tuple[Literal['storage'], Literal['process_control']] = (
REQUIRED_KEYS: tuple[str, str] = (
KEY_STORAGE,
KEY_PROCESS,
)

def __init__(
self, name: str, config: Mapping[str, Any], config_folder: pathlib.Path | None = None, validate: bool = True
self, name: str, config: abc.Mapping[str, Any], config_folder: pathlib.Path | None = None, validate: bool = True
):
"""Load a profile with the profile configuration."""
_ = type_check(config, abc.Mapping)
Expand All @@ -59,7 +59,7 @@ def __init__(
)

self._name: str = name
self._attributes: Dict[str, Any] = deepcopy(config)
self._attributes: dict[str, Any] = cast(dict[str, Any], deepcopy(config))

# Create a default UUID if not specified
if self._attributes.get(self.KEY_UUID, None) is None:
Expand Down Expand Up @@ -93,17 +93,13 @@ def config_path_resolver(self) -> AiiDAConfigPathResolver:
"""The config_path_resolver property."""
return self._config_path_resolver

@config_path_resolver.setter
def config_path_resolver(self, value):
self._config_path_resolver = value

@property
def default_user_email(self) -> Optional[str]:
def default_user_email(self) -> str | None:
"""Return the default user email."""
return self._attributes.get(self.KEY_DEFAULT_USER_EMAIL, None)

@default_user_email.setter
def default_user_email(self, value: Optional[str]) -> None:
def default_user_email(self, value: str | None) -> None:
"""Set the default user email."""
self._attributes[self.KEY_DEFAULT_USER_EMAIL] = value

Expand All @@ -113,11 +109,11 @@ def storage_backend(self) -> str:
return self._attributes[self.KEY_STORAGE][self.KEY_STORAGE_BACKEND]

@property
def storage_config(self) -> Dict[str, Any]:
def storage_config(self) -> dict[str, Any]:
"""Return the configuration required by the storage backend."""
return self._attributes[self.KEY_STORAGE][self.KEY_STORAGE_CONFIG]

def set_storage(self, name: str, config: Dict[str, Any]) -> None:
def set_storage(self, name: str, config: dict[str, Any]) -> None:
"""Set the storage backend and its configuration.
:param name: the name of the storage backend
Expand All @@ -128,7 +124,7 @@ def set_storage(self, name: str, config: Dict[str, Any]) -> None:
self._attributes[self.KEY_STORAGE][self.KEY_STORAGE_CONFIG] = config

@property
def storage_cls(self) -> Type['StorageBackend']:
def storage_cls(self) -> type['StorageBackend']:
"""Return the storage backend class for this profile."""
from aiida.plugins import StorageFactory

Expand All @@ -140,11 +136,11 @@ def process_control_backend(self) -> str | None:
return self._attributes[self.KEY_PROCESS][self.KEY_PROCESS_BACKEND]

@property
def process_control_config(self) -> Dict[str, Any]:
def process_control_config(self) -> dict[str, Any]:
"""Return the configuration required by the process control backend."""
return self._attributes[self.KEY_PROCESS][self.KEY_PROCESS_CONFIG] or {}

def set_process_controller(self, name: str, config: Dict[str, Any]) -> None:
def set_process_controller(self, name: str, config: dict[str, Any]) -> None:
"""Set the process control backend and its configuration.
:param name: the name of the process backend
Expand Down Expand Up @@ -189,7 +185,7 @@ def name(self):
return self._name

@property
def dictionary(self) -> Dict[str, Any]:
def dictionary(self) -> dict[str, Any]:
"""Return the profile attributes as a dictionary with keys as it is stored in the config
:return: the profile configuration dictionary
Expand Down

0 comments on commit 1b26044

Please sign in to comment.