mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-10-30 23:47:40 +03:00 
			
		
		
		
	Add warning on extra @inject
				
					
				
			This commit is contained in:
		
							parent
							
								
									e6cc12762f
								
							
						
					
					
						commit
						04b5907f21
					
				|  | @ -108,6 +108,7 @@ markers = [ | |||
|     "pydantic: Tests with Pydantic as a dependency", | ||||
| ] | ||||
| filterwarnings = [ | ||||
|     "ignore::dependency_injector.wiring.DIWiringWarning", | ||||
|     "ignore:Module \"dependency_injector.ext.aiohttp\" is deprecated since version 4\\.0\\.0:DeprecationWarning", | ||||
|     "ignore:Module \"dependency_injector.ext.flask\" is deprecated since version 4\\.0\\.0:DeprecationWarning", | ||||
|     "ignore:Please use \\`.*?\\` from the \\`scipy.*?\\`(.*?)namespace is deprecated\\.:DeprecationWarning", | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| """Top-level package.""" | ||||
| 
 | ||||
| __version__ = "4.48.0" | ||||
| __version__ = "4.48.1" | ||||
| """Version number. | ||||
| 
 | ||||
| :type: str | ||||
|  |  | |||
|  | @ -24,6 +24,7 @@ from typing import ( | |||
|     Union, | ||||
|     cast, | ||||
| ) | ||||
| from warnings import warn | ||||
| 
 | ||||
| try: | ||||
|     from typing import Self | ||||
|  | @ -130,6 +131,10 @@ else: | |||
|     Container = Any | ||||
| 
 | ||||
| 
 | ||||
| class DIWiringWarning(RuntimeWarning): | ||||
|     """Base class for all warnings raised by the wiring module.""" | ||||
| 
 | ||||
| 
 | ||||
| class PatchedRegistry: | ||||
| 
 | ||||
|     def __init__(self) -> None: | ||||
|  | @ -520,6 +525,11 @@ def unwire(  # noqa: C901 | |||
| def inject(fn: F) -> F: | ||||
|     """Decorate callable with injecting decorator.""" | ||||
|     reference_injections, reference_closing = _fetch_reference_injections(fn) | ||||
| 
 | ||||
|     if not reference_injections: | ||||
|         warn("@inject is not required here", DIWiringWarning, stacklevel=2) | ||||
|         return fn | ||||
| 
 | ||||
|     patched = _get_patched(fn, reference_injections, reference_closing) | ||||
|     return cast(F, patched) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user