Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 04b5907

Browse files
committed
Add warning on extra @inject
1 parent e6cc127 commit 04b5907

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

‎pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ markers = [
108108
"pydantic: Tests with Pydantic as a dependency",
109109
]
110110
filterwarnings = [
111+
"ignore::dependency_injector.wiring.DIWiringWarning",
111112
"ignore:Module \"dependency_injector.ext.aiohttp\" is deprecated since version 4\\.0\\.0:DeprecationWarning",
112113
"ignore:Module \"dependency_injector.ext.flask\" is deprecated since version 4\\.0\\.0:DeprecationWarning",
113114
"ignore:Please use \\`.*?\\` from the \\`scipy.*?\\`(.*?)namespace is deprecated\\.:DeprecationWarning",

‎src/dependency_injector/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Top-level package."""
22

3-
__version__ = "4.48.0"
3+
__version__ = "4.48.1"
44
"""Version number.
55
66
:type: str

‎src/dependency_injector/wiring.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
Union,
2525
cast,
2626
)
27+
from warnings import warn
2728

2829
try:
2930
from typing import Self
@@ -130,6 +131,10 @@ def extract_marker_from_fast_depends(param: Any) -> Any:
130131
Container = Any
131132

132133

134+
class DIWiringWarning(RuntimeWarning):
135+
"""Base class for all warnings raised by the wiring module."""
136+
137+
133138
class PatchedRegistry:
134139

135140
def __init__(self) -> None:
@@ -520,6 +525,11 @@ def unwire( # noqa: C901
520525
def inject(fn: F) -> F:
521526
"""Decorate callable with injecting decorator."""
522527
reference_injections, reference_closing = _fetch_reference_injections(fn)
528+
529+
if not reference_injections:
530+
warn("@inject is not required here", DIWiringWarning, stacklevel=2)
531+
return fn
532+
523533
patched = _get_patched(fn, reference_injections, reference_closing)
524534
return cast(F, patched)
525535

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /