Skip to content

Commit

Permalink
Typing: mypy fix for orm.List the pop and index methods (#6635)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
unkcpz authored Nov 26, 2024
1 parent ec8a055 commit 36eab77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/aiida/orm/nodes/data/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/aiida/tools/pytest_fixtures/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 36eab77

Please sign in to comment.