Skip to content

Commit 9c4b7b2

Browse files
committed
fix: Fixed level of injection warnings when annotating functions without dependencies.
1 parent f2e4bdc commit 9c4b7b2

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

docs/introduction/injection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ This is to avoid accidentally decorating a function that doesn’t actually requ
100100

101101
## Specifying a Scope
102102

103-
By default, `@inject` enters the scope `ContextScopes.INJECT`. If you want to override that, do:
103+
By default, `@inject` uses the `ContextScopes.INJECT` scope. If you want to override that, do:
104104

105105
```python
106106
from that_depends import inject

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dev = [
4747
"mkdocs>=1.6.1",
4848
"pytest-randomly",
4949
"mkdocs-llmstxt>=0.4.0",
50+
"pydantic<2.12.4" # causes tests to fail because of: TypeError: _eval_type() got an unexpected keyword argument 'prefer_fwd_module'
5051
]
5152

5253
[build-system]

that_depends/injection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def inner(*args: P.args, **kwargs: P.kwargs) -> typing.Generator[T, typing.Any,
9494
injected, kwargs = _resolve_arguments_sync(signature, scope, container, None, *args, **kwargs) # type: ignore[assignment]
9595

9696
if not injected:
97-
warnings.warn(_INJECTION_WARNING_MESSAGE, RuntimeWarning, stacklevel=1)
97+
warnings.warn(_INJECTION_WARNING_MESSAGE, RuntimeWarning, stacklevel=2)
9898

9999
g = gen(*args, **kwargs)
100100
result = yield from g
@@ -249,7 +249,7 @@ def _resolve_sync(
249249
injected, kwargs = _resolve_arguments_sync(signature, scope, container, stack, *args, **kwargs) # type: ignore[assignment]
250250

251251
if not injected:
252-
warnings.warn(_INJECTION_WARNING_MESSAGE, RuntimeWarning, stacklevel=1)
252+
warnings.warn(_INJECTION_WARNING_MESSAGE, RuntimeWarning, stacklevel=3)
253253

254254
return func(*args, **kwargs)
255255

0 commit comments

Comments
 (0)