python-injection 0.8.4.post2__tar.gz → 0.8.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of python-injection might be problematic. Click here for more details.
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/PKG-INFO +1 -1
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/core/module.py +19 -11
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/pyproject.toml +1 -1
- python_injection-0.8.4.post2/injection/common/queue.py +0 -63
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/documentation/basic-usage.md +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/__init__.py +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/__init__.pyi +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/common/__init__.py +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/common/event.py +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/common/invertible.py +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/common/lazy.py +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/common/tools/__init__.py +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/common/tools/threading.py +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/common/tools/type.py +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/core/__init__.py +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/exceptions.py +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/integrations/__init__.py +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/integrations/blacksheep.py +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/py.typed +0 -0
- {python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/utils.py +0 -0
|
@@ -17,6 +17,7 @@ from dataclasses import dataclass, field
|
|
|
17
17
|
from enum import Enum
|
|
18
18
|
from functools import partialmethod, singledispatchmethod, update_wrapper
|
|
19
19
|
from inspect import Signature, isclass
|
|
20
|
+
from queue import Queue
|
|
20
21
|
from types import MethodType, UnionType
|
|
21
22
|
from typing import (
|
|
22
23
|
Any,
|
|
@@ -33,7 +34,6 @@ from typing import (
|
|
|
33
34
|
from injection.common.event import Event, EventChannel, EventListener
|
|
34
35
|
from injection.common.invertible import Invertible, SimpleInvertible
|
|
35
36
|
from injection.common.lazy import Lazy, LazyMapping
|
|
36
|
-
from injection.common.queue import LimitedQueue
|
|
37
37
|
from injection.common.tools.threading import synchronized
|
|
38
38
|
from injection.common.tools.type import find_types, format_type, get_origins
|
|
39
39
|
from injection.exceptions import (
|
|
@@ -51,7 +51,6 @@ _logger = logging.getLogger(__name__)
|
|
|
51
51
|
_T = TypeVar("_T")
|
|
52
52
|
_T_co = TypeVar("_T_co", covariant=True)
|
|
53
53
|
|
|
54
|
-
|
|
55
54
|
"""
|
|
56
55
|
Events
|
|
57
56
|
"""
|
|
@@ -684,8 +683,10 @@ class InjectedFunction(EventListener):
|
|
|
684
683
|
update_wrapper(self, wrapped, updated=())
|
|
685
684
|
self.__dependencies = Dependencies.empty()
|
|
686
685
|
self.__owner = None
|
|
687
|
-
|
|
688
|
-
|
|
686
|
+
|
|
687
|
+
queue = Queue[Callable[[], Any]]()
|
|
688
|
+
queue.put_nowait(self.__set_signature)
|
|
689
|
+
self.__setup_queue = queue
|
|
689
690
|
|
|
690
691
|
def __repr__(self) -> str: # pragma: no cover
|
|
691
692
|
return repr(self.wrapped)
|
|
@@ -694,8 +695,12 @@ class InjectedFunction(EventListener):
|
|
|
694
695
|
return str(self.wrapped)
|
|
695
696
|
|
|
696
697
|
def __call__(self, /, *args, **kwargs) -> Any:
|
|
697
|
-
|
|
698
|
-
|
|
698
|
+
queue = self.__setup_queue
|
|
699
|
+
|
|
700
|
+
while not queue.empty():
|
|
701
|
+
setup = queue.get()
|
|
702
|
+
setup()
|
|
703
|
+
queue.task_done()
|
|
699
704
|
|
|
700
705
|
arguments = self.bind(args, kwargs)
|
|
701
706
|
return self.wrapped(*arguments.args, **arguments.kwargs)
|
|
@@ -753,7 +758,7 @@ class InjectedFunction(EventListener):
|
|
|
753
758
|
|
|
754
759
|
def on_setup(self, wrapped: Callable[[], Any] = None, /):
|
|
755
760
|
def decorator(wp):
|
|
756
|
-
self.__setup_queue.
|
|
761
|
+
self.__setup_queue.put(wp)
|
|
757
762
|
return wp
|
|
758
763
|
|
|
759
764
|
return decorator(wrapped) if wrapped else decorator
|
|
@@ -781,12 +786,15 @@ class InjectedFunction(EventListener):
|
|
|
781
786
|
self.__update_vars(variables)
|
|
782
787
|
|
|
783
788
|
def __update_vars(self, variables: Mapping[str, Any]):
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
restricted_vars = frozenset(var for var in dir(self) if not is_dunder(var))
|
|
789
|
+
restricted_vars = frozenset(
|
|
790
|
+
var for var in dir(self) if not self.__is_dunder(var)
|
|
791
|
+
)
|
|
788
792
|
vars(self).update(
|
|
789
793
|
(var, value)
|
|
790
794
|
for var, value in variables.items()
|
|
791
795
|
if var not in restricted_vars
|
|
792
796
|
)
|
|
797
|
+
|
|
798
|
+
@staticmethod
|
|
799
|
+
def __is_dunder(var: str) -> bool:
|
|
800
|
+
return var.startswith("__") and var.endswith("__")
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
from abc import abstractmethod
|
|
2
|
-
from collections import deque
|
|
3
|
-
from collections.abc import Iterator
|
|
4
|
-
from dataclasses import dataclass, field
|
|
5
|
-
from typing import NoReturn, Protocol, TypeVar
|
|
6
|
-
|
|
7
|
-
__all__ = ("LimitedQueue",)
|
|
8
|
-
|
|
9
|
-
_T = TypeVar("_T")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class Queue(Iterator[_T], Protocol):
|
|
13
|
-
__slots__ = ()
|
|
14
|
-
|
|
15
|
-
@abstractmethod
|
|
16
|
-
def add(self, item: _T):
|
|
17
|
-
raise NotImplementedError
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@dataclass(repr=False, frozen=True, slots=True)
|
|
21
|
-
class SimpleQueue(Queue[_T]):
|
|
22
|
-
__items: deque[_T] = field(default_factory=deque, init=False)
|
|
23
|
-
|
|
24
|
-
def __next__(self) -> _T:
|
|
25
|
-
try:
|
|
26
|
-
return self.__items.popleft()
|
|
27
|
-
except IndexError as exc:
|
|
28
|
-
raise StopIteration from exc
|
|
29
|
-
|
|
30
|
-
def add(self, item: _T):
|
|
31
|
-
self.__items.append(item)
|
|
32
|
-
return self
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class DeadQueue(Queue[_T]):
|
|
36
|
-
__slots__ = ()
|
|
37
|
-
|
|
38
|
-
def __bool__(self) -> bool:
|
|
39
|
-
return False
|
|
40
|
-
|
|
41
|
-
def __next__(self) -> NoReturn:
|
|
42
|
-
raise StopIteration
|
|
43
|
-
|
|
44
|
-
def add(self, item: _T) -> NoReturn:
|
|
45
|
-
raise TypeError("Queue is dead.")
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
@dataclass(repr=False, slots=True)
|
|
49
|
-
class LimitedQueue(Queue[_T]):
|
|
50
|
-
__state: Queue[_T] = field(default_factory=SimpleQueue)
|
|
51
|
-
|
|
52
|
-
def __next__(self) -> _T:
|
|
53
|
-
try:
|
|
54
|
-
return next(self.__state)
|
|
55
|
-
except StopIteration as exc:
|
|
56
|
-
if self.__state:
|
|
57
|
-
self.__state = DeadQueue()
|
|
58
|
-
|
|
59
|
-
raise exc
|
|
60
|
-
|
|
61
|
-
def add(self, item: _T):
|
|
62
|
-
self.__state.add(item)
|
|
63
|
-
return self
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_injection-0.8.4.post2 → python_injection-0.8.5}/injection/integrations/blacksheep.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|