Skip to content

Commit 817bfba

Browse files
authored
refactoring: ♻️ Hook now uses a deque
1 parent 53bacb3 commit 817bfba

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

injection/_core/hook.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import itertools
2+
from collections import deque
23
from collections.abc import Callable, Generator, Iterator
34
from dataclasses import dataclass, field
45
from inspect import isclass, isgeneratorfunction
@@ -13,8 +14,8 @@
1314

1415
@dataclass(eq=False, frozen=True, slots=True)
1516
class Hook[**P, T]:
16-
__functions: list[HookFunction[P, T]] = field(
17-
default_factory=list,
17+
__functions: deque[HookFunction[P, T]] = field(
18+
default_factory=deque,
1819
init=False,
1920
repr=False,
2021
)
@@ -35,7 +36,7 @@ def __stack(self) -> Iterator[HookFunction[P, T]]:
3536
return iter(self.__functions)
3637

3738
def add(self, *functions: HookFunction[P, T]) -> Self:
38-
self.__functions.extend(reversed(functions))
39+
self.__functions.extendleft(functions)
3940
return self
4041

4142
@classmethod

0 commit comments

Comments
 (0)