Skip to content

Commit 7d46ef9

Browse files
committed
Rename @wiring.injected -> inject
1 parent 588b2f2 commit 7d46ef9

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ With this approach you can automatically inject functions at load time using the
3131
from pif import wiring, providers
3232

3333

34-
@wiring.injected # <- automatically injects providers.Provider default arguments!
34+
@wiring.inject # <- automatically injects providers.Provider default arguments!
3535
def my_function(a: str = providers.ExistingSingleton("hello world")):
3636
return a
3737

@@ -74,7 +74,7 @@ from pif import wiring, providers
7474
StringProvider = providers.ExistingSingleton("hello world")
7575

7676

77-
@wiring.injected
77+
@wiring.inject
7878
def my_function(a: str = StringProvider):
7979
return a
8080

@@ -97,7 +97,7 @@ from pif import wiring, providers
9797
StringProvider = providers.ExistingSingleton("hello world")
9898

9999

100-
@wiring.injected
100+
@wiring.inject
101101
def my_function(a: str = StringProvider):
102102
return a
103103

examples/simple_service/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def do_stuff(self): ...
1818
ApiClientProvider = providers.Singleton[ApiClient](ApiClient, domain=ApiDomainProvider, token=ApiTokenProvider)
1919

2020

21-
@wiring.injected
21+
@wiring.inject
2222
def main(client: ApiClient = ApiClientProvider):
2323
"""
2424
Your application logic.

pif/wiring.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def patch_args(
4747
return args, kwargs
4848

4949

50-
def injected[T: Callable](func: T) -> T:
50+
def inject[T: Callable](func: T) -> T:
5151
"""
5252
Get a decorated copy of `func` with patched arguments.
5353
@@ -89,7 +89,7 @@ def patch_method[T: Callable | types.FunctionType](func: T) -> T:
8989
:return: a "patched" version of the method provided.
9090
"""
9191
if any(1 for param in inspect.signature(func).parameters.values() if isinstance(param.default, providers.Provider)):
92-
return injected(func)
92+
return inject(func)
9393

9494
return func
9595

tests/test_wiring.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_patch_lazy():
4848
mock = MagicMock()
4949
assert not mock.call_count
5050

51-
@wiring.injected
51+
@wiring.inject
5252
def func(v=providers.Singleton[MagicMock](lambda: mock)):
5353
return v()
5454

@@ -64,14 +64,14 @@ def test_patch_positional_only():
6464
Test patching for POSITIONAL_ONLY arguments.
6565
"""
6666

67-
@wiring.injected
67+
@wiring.inject
6868
def p1(a, b=provide("b"), c="c_default", /):
6969
return a, b, c
7070

7171
assert p1(None) == (None, "b_injected", "c_default")
7272
assert p1(None, None) == (None, None, "c_default")
7373

74-
@wiring.injected
74+
@wiring.inject
7575
def p2(a, b=None, c=provide("c"), /):
7676
return a, b, c
7777

@@ -85,7 +85,7 @@ def test_patch_positional():
8585
Test patching for POSITIONAL_OR_KEYWORD arguments.
8686
"""
8787

88-
@wiring.injected
88+
@wiring.inject
8989
def p1(a, b=provide("b"), c="c_default"):
9090
return a, b, c
9191

@@ -94,7 +94,7 @@ def p1(a, b=provide("b"), c="c_default"):
9494
assert p1(a=None) == (None, "b_injected", "c_default")
9595
assert p1(a=None, b=None) == (None, None, "c_default")
9696

97-
@wiring.injected
97+
@wiring.inject
9898
def p2(a, b=None, c=provide("c")):
9999
return a, b, c
100100

@@ -111,7 +111,7 @@ def test_patch_positional_or_keyword():
111111
Test patching for VAR_POSITIONAL argument.
112112
"""
113113

114-
@wiring.injected
114+
@wiring.inject
115115
def p1(a, b=provide("b"), *c, d="d_default", e=provide("e")):
116116
return a, b, *c, d, e
117117

0 commit comments

Comments
 (0)