From 36eab779793a6dd0184c83f0b0af6a75a62fac82 Mon Sep 17 00:00:00 2001 From: Jusong Yu Date: Tue, 26 Nov 2024 14:48:52 +0100 Subject: [PATCH] Typing: mypy fix for `orm.List` the `pop` and `index` methods (#6635) The function signature of `pop` and `index` methods of `orm.List` is updated to synchronous with `MutableSequence` which it inherit from. The implementation of `orm.List` is expected to be the same as vanilla python `list` type. The new function signature has the index parameter for `pop` with default `-1` for pop the last element from the list. This change might be a break change because the previous implementation can be used differently. --- src/aiida/orm/nodes/data/list.py | 7 ++++--- src/aiida/tools/pytest_fixtures/daemon.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/aiida/orm/nodes/data/list.py b/src/aiida/orm/nodes/data/list.py index fc39dd1acd..d2c0857b35 100644 --- a/src/aiida/orm/nodes/data/list.py +++ b/src/aiida/orm/nodes/data/list.py @@ -9,6 +9,7 @@ """`Data` sub class to represent a list.""" from collections.abc import MutableSequence +from typing import Any from .base import to_aiida_type from .data import Data @@ -81,15 +82,15 @@ def remove(self, value): self.set_list(data) return item - def pop(self, **kwargs): # type: ignore[override] + def pop(self, index: int = -1) -> Any: """Remove and return item at index (default last).""" data = self.get_list() - item = data.pop(**kwargs) + item = data.pop(index) if not self._using_list_reference(): self.set_list(data) return item - def index(self, value): # type: ignore[override] + def index(self, value: Any, start: int = 0, stop: int = 0) -> int: """Return first index of value..""" return self.get_list().index(value) diff --git a/src/aiida/tools/pytest_fixtures/daemon.py b/src/aiida/tools/pytest_fixtures/daemon.py index 2b74e4ce77..89ef02d841 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: type[Process] | ProcessBuilder | ProcessNode | t.Any, + submittable: type[Process] | ProcessBuilder | ProcessNode, state: ProcessState = ProcessState.FINISHED, timeout: int = 20, **kwargs,