Skip to content

Commit 1b26044

Browse files
committed
src/aiida/manage/configuration/profile.py out of mypy exclude list
1 parent 5ed4950 commit 1b26044

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

.pre-commit-config.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ repos:
124124
src/aiida/engine/processes/ports.py|
125125
src/aiida/manage/configuration/__init__.py|
126126
src/aiida/manage/configuration/config.py|
127-
src/aiida/manage/configuration/profile.py|
128127
src/aiida/manage/external/rmq/launcher.py|
129128
src/aiida/manage/tests/main.py|
130129
src/aiida/manage/tests/pytest_fixtures.py|

src/aiida/common/lang.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def isidentifier(identifier):
2323
return identifier.isidentifier() and not keyword.iskeyword(identifier)
2424

2525

26-
def type_check(what, of_type, msg=None, allow_none=False):
26+
def type_check(
27+
what: object, of_type, msg: str | None = None, allow_none: bool = False
28+
) -> object | None:
2729
"""Verify that object 'what' is of type 'of_type' and if not the case, raise a TypeError.
2830
2931
:param what: the object to check

src/aiida/manage/configuration/profile.py

+12-16
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import pathlib
1515
from collections import abc
1616
from copy import deepcopy
17-
from typing import TYPE_CHECKING, Any, Dict, Literal, Mapping, Optional, Type
17+
from typing import TYPE_CHECKING, Any, Literal, cast
1818

1919
from aiida.common import exceptions
2020
from aiida.common.lang import type_check
@@ -43,13 +43,13 @@ class Profile:
4343
KEY_TEST_PROFILE: str = 'test_profile'
4444

4545
# keys that are expected to be in the parsed configuration
46-
REQUIRED_KEYS: tuple[Literal['storage'], Literal['process_control']] = (
46+
REQUIRED_KEYS: tuple[str, str] = (
4747
KEY_STORAGE,
4848
KEY_PROCESS,
4949
)
5050

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

6161
self._name: str = name
62-
self._attributes: Dict[str, Any] = deepcopy(config)
62+
self._attributes: dict[str, Any] = cast(dict[str, Any], deepcopy(config))
6363

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

96-
@config_path_resolver.setter
97-
def config_path_resolver(self, value):
98-
self._config_path_resolver = value
99-
10096
@property
101-
def default_user_email(self) -> Optional[str]:
97+
def default_user_email(self) -> str | None:
10298
"""Return the default user email."""
10399
return self._attributes.get(self.KEY_DEFAULT_USER_EMAIL, None)
104100

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

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

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

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

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

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

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

147-
def set_process_controller(self, name: str, config: Dict[str, Any]) -> None:
143+
def set_process_controller(self, name: str, config: dict[str, Any]) -> None:
148144
"""Set the process control backend and its configuration.
149145
150146
:param name: the name of the process backend
@@ -189,7 +185,7 @@ def name(self):
189185
return self._name
190186

191187
@property
192-
def dictionary(self) -> Dict[str, Any]:
188+
def dictionary(self) -> dict[str, Any]:
193189
"""Return the profile attributes as a dictionary with keys as it is stored in the config
194190
195191
:return: the profile configuration dictionary

0 commit comments

Comments
 (0)