mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-10-31 16:07:51 +03:00 
			
		
		
		
	fixup! Add support for Fast Stream Depends
This commit is contained in:
		
							parent
							
								
									aaf9878266
								
							
						
					
					
						commit
						ea5830a929
					
				|  | @ -3,6 +3,7 @@ import sys | |||
| from dependency_injector import containers, providers | ||||
| from dependency_injector.wiring import inject, Provide | ||||
| from fast_depends import Depends | ||||
| from typing_extensions import Annotated | ||||
| 
 | ||||
| 
 | ||||
| class CoefficientService: | ||||
|  | @ -23,5 +24,13 @@ def apply_coefficient( | |||
|     return a * coefficient_provider.get_coefficient() | ||||
| 
 | ||||
| 
 | ||||
| @inject | ||||
| def apply_coefficient_annotated( | ||||
|     a: int, | ||||
|     coefficient_provider: Annotated[CoefficientService, Depends(Provide[Container.service])], | ||||
| ) -> float: | ||||
|     return a * coefficient_provider.get_coefficient() | ||||
| 
 | ||||
| 
 | ||||
| container = Container() | ||||
| container.wire(modules=[sys.modules[__name__]]) | ||||
|  | @ -3,5 +3,9 @@ from dependency_injector.wiring import inject, Provide | |||
| from wiringfastdepends import sample | ||||
| 
 | ||||
| 
 | ||||
| def test_apply_coefficient(): | ||||
|     assert sample.apply_coefficient(100) == 120.0 | ||||
| def test_apply_coefficient() -> None: | ||||
|     assert sample.apply_coefficient(100) == 120.0 | ||||
| 
 | ||||
| 
 | ||||
| def test_apply_coefficient_annotated() -> None: | ||||
|     assert sample.apply_coefficient_annotated(100) == 120.0 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user