diff --git a/pyproject.toml b/pyproject.toml index 3768fcb05c..6b3f630e1a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -211,7 +211,7 @@ notebook = [ ] pre-commit = [ 'aiida-core[atomic_tools,rest,tests,tui]', - 'mypy~=1.10.0', + 'mypy~=1.13.0', 'packaging~=23.0', 'pre-commit~=3.5', 'sqlalchemy[mypy]~=2.0', diff --git a/src/aiida/common/lang.py b/src/aiida/common/lang.py index ec9fb45ddb..6a8f4d3d5b 100644 --- a/src/aiida/common/lang.py +++ b/src/aiida/common/lang.py @@ -96,4 +96,4 @@ def __init__(self, getter: Callable[[SelfType], ReturnType]) -> None: self.getter = getter def __get__(self, instance: Any, owner: SelfType) -> ReturnType: - return self.getter(owner) + return self.getter(owner) # type: ignore[arg-type] diff --git a/src/aiida/common/pydantic.py b/src/aiida/common/pydantic.py index 633e83428d..2fa3d2bd68 100644 --- a/src/aiida/common/pydantic.py +++ b/src/aiida/common/pydantic.py @@ -41,7 +41,7 @@ class Model(BaseModel): field_info = Field(default, **kwargs) for key, value in (('priority', priority), ('short_name', short_name), ('option_cls', option_cls)): - if value is not None: + if value is not None and field_info is not None: field_info.metadata.append({key: value}) return field_info diff --git a/src/aiida/engine/processes/calcjobs/calcjob.py b/src/aiida/engine/processes/calcjobs/calcjob.py index d5acfca5fc..8ced783a5f 100644 --- a/src/aiida/engine/processes/calcjobs/calcjob.py +++ b/src/aiida/engine/processes/calcjobs/calcjob.py @@ -1062,7 +1062,7 @@ def presubmit(self, folder: Folder) -> CalcInfo: def encoder(obj): if dataclasses.is_dataclass(obj): - return dataclasses.asdict(obj) + return dataclasses.asdict(obj) # type: ignore[arg-type] raise TypeError(f' {obj!r} is not JSON serializable') subfolder = folder.get_subfolder('.aiida', create=True) diff --git a/src/aiida/engine/processes/workchains/restart.py b/src/aiida/engine/processes/workchains/restart.py index ad5cd8a181..34544704f2 100644 --- a/src/aiida/engine/processes/workchains/restart.py +++ b/src/aiida/engine/processes/workchains/restart.py @@ -29,7 +29,7 @@ def validate_handler_overrides( - process_class: 'BaseRestartWorkChain', handler_overrides: Optional[orm.Dict], ctx: 'PortNamespace' + process_class: type['BaseRestartWorkChain'], handler_overrides: Optional[orm.Dict], ctx: 'PortNamespace' ) -> Optional[str]: """Validator for the ``handler_overrides`` input port of the ``BaseRestartWorkChain``. diff --git a/src/aiida/manage/manager.py b/src/aiida/manage/manager.py index 8621b324f4..651190454e 100644 --- a/src/aiida/manage/manager.py +++ b/src/aiida/manage/manager.py @@ -430,7 +430,7 @@ def create_runner(self, with_persistence: bool = True, **kwargs: Any) -> 'Runner if with_persistence and 'persister' not in settings: settings['persister'] = self.get_persister() - return runners.Runner(**settings) + return runners.Runner(**settings) # type: ignore[arg-type] def create_daemon_runner(self, loop: Optional['asyncio.AbstractEventLoop'] = None) -> 'Runner': """Create and return a new daemon runner. diff --git a/src/aiida/orm/nodes/data/array/projection.py b/src/aiida/orm/nodes/data/array/projection.py index e58442d9c5..881ac727c2 100644 --- a/src/aiida/orm/nodes/data/array/projection.py +++ b/src/aiida/orm/nodes/data/array/projection.py @@ -278,7 +278,7 @@ def array_list_checker(array_list, array_name, orb_length): raise exceptions.ValidationError('Tags must set a list of strings') self.base.attributes.set('tags', tags) - def set_orbitals(self, **kwargs): + def set_orbitals(self, **kwargs): # type: ignore[override] """This method is inherited from OrbitalData, but is blocked here. If used will raise a NotImplementedError """ diff --git a/src/aiida/orm/nodes/data/list.py b/src/aiida/orm/nodes/data/list.py index 9fdd6ec866..fc39dd1acd 100644 --- a/src/aiida/orm/nodes/data/list.py +++ b/src/aiida/orm/nodes/data/list.py @@ -81,7 +81,7 @@ def remove(self, value): self.set_list(data) return item - def pop(self, **kwargs): + def pop(self, **kwargs): # type: ignore[override] """Remove and return item at index (default last).""" data = self.get_list() item = data.pop(**kwargs) @@ -89,7 +89,7 @@ def pop(self, **kwargs): self.set_list(data) return item - def index(self, value): + def index(self, value): # type: ignore[override] """Return first index of value..""" return self.get_list().index(value) diff --git a/src/aiida/orm/nodes/data/singlefile.py b/src/aiida/orm/nodes/data/singlefile.py index c0f3797f24..8faefc8cb4 100644 --- a/src/aiida/orm/nodes/data/singlefile.py +++ b/src/aiida/orm/nodes/data/singlefile.py @@ -71,9 +71,7 @@ def open(self, path: FilePath, mode: t.Literal['rb']) -> t.Iterator[t.BinaryIO]: @t.overload @contextlib.contextmanager - def open( # type: ignore[overload-overlap] - self, path: None = None, mode: t.Literal['r'] = ... - ) -> t.Iterator[t.TextIO]: ... + def open(self, path: None = None, mode: t.Literal['r'] = ...) -> t.Iterator[t.TextIO]: ... @t.overload @contextlib.contextmanager diff --git a/src/aiida/plugins/utils.py b/src/aiida/plugins/utils.py index c284b25912..7d1e16a363 100644 --- a/src/aiida/plugins/utils.py +++ b/src/aiida/plugins/utils.py @@ -38,7 +38,7 @@ def __init__(self): def logger(self) -> Logger: return self._logger - def get_version_info(self, plugin: str | type) -> dict[t.Any, dict[t.Any, t.Any]]: + def get_version_info(self, plugin: str | t.Any) -> dict[t.Any, dict[t.Any, t.Any]]: """Get the version information for a given plugin. .. note:: diff --git a/src/aiida/tools/pytest_fixtures/daemon.py b/src/aiida/tools/pytest_fixtures/daemon.py index 74e3620193..2b74e4ce77 100644 --- a/src/aiida/tools/pytest_fixtures/daemon.py +++ b/src/aiida/tools/pytest_fixtures/daemon.py @@ -116,7 +116,7 @@ def test(submit_and_await): from aiida.engine import ProcessState def factory( - submittable: 'Process' | 'ProcessBuilder' | 'ProcessNode', + submittable: type[Process] | ProcessBuilder | ProcessNode | t.Any, state: ProcessState = ProcessState.FINISHED, timeout: int = 20, **kwargs, diff --git a/tests/cmdline/groups/test_dynamic.py b/tests/cmdline/groups/test_dynamic.py index 3c741b8fe2..48c18f0941 100644 --- a/tests/cmdline/groups/test_dynamic.py +++ b/tests/cmdline/groups/test_dynamic.py @@ -17,7 +17,7 @@ class Model(BaseModel): union_type: t.Union[int, float] = Field(title='Union type') without_default: str = Field(title='Without default') with_default: str = Field(title='With default', default='default') - with_default_factory: str = Field(title='With default factory', default_factory=lambda: True) + with_default_factory: str = Field(title='With default factory', default_factory=lambda: True) # type: ignore[assignment] def test_list_options(entry_points):