Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion documentation/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class SomeDataClass:

### Threadsafe injection

With `threadsafe=True`, the injection logic is wrapped in a `threading.Lock`.
With `threadsafe=True`, the injection logic is wrapped in a `threading.RLock`.
Comment thread
remimd marked this conversation as resolved.

```python
@inject(threadsafe=True)
Expand Down
6 changes: 4 additions & 2 deletions injection/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class LazyInstance[T]:
cls: _InputType[T],
/,
default: T = ...,
*,
module: Module = ...,
threadsafe: bool = ...,
) -> None: ...
@overload
def __get__(self, instance: object, owner: type | None = ...) -> T: ...
Expand Down Expand Up @@ -292,8 +294,8 @@ class Module:
) -> _Invertible[T | Default]:
"""
Function used to retrieve an instance associated with the type passed in
parameter or `NotImplemented`. Return a `Invertible` object. To access the instance
contained in an invertible object, simply use a wavy line (~).
parameter or `NotImplemented`. Return an `Invertible` object. To access the
instance contained in an invertible object, simply use a wavy line (~).

Example: instance = ~lazy_instance
"""
Expand Down
5 changes: 4 additions & 1 deletion injection/_core/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ def __init__(
cls: InputType[T],
/,
default: T = NotImplemented,
*,
module: Module | None = None,
threadsafe: bool = False,
Comment thread
remimd marked this conversation as resolved.
) -> None:
self.__value = (module or mod()).get_lazy_instance(cls, default)
module = module or mod()
self.__value = module.get_lazy_instance(cls, default, threadsafe=threadsafe)

def __get__(
self,
Expand Down