diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 32305828b4..084d4b3423 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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| diff --git a/src/aiida/common/lang.py b/src/aiida/common/lang.py index ec9fb45ddb..251db3e6fd 100644 --- a/src/aiida/common/lang.py +++ b/src/aiida/common/lang.py @@ -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 diff --git a/src/aiida/manage/configuration/profile.py b/src/aiida/manage/configuration/profile.py index 5d56a94201..875d89b4e2 100644 --- a/src/aiida/manage/configuration/profile.py +++ b/src/aiida/manage/configuration/profile.py @@ -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 @@ -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) @@ -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: @@ -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 @@ -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 @@ -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 @@ -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 @@ -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