mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-10-31 07:57:43 +03:00 
			
		
		
		
	Add support for Fast Stream Depends
This commit is contained in:
		
							parent
							
								
									8460465b5e
								
							
						
					
					
						commit
						2fe4c393a8
					
				|  | @ -66,6 +66,12 @@ except ImportError: | |||
|     werkzeug = None | ||||
| 
 | ||||
| 
 | ||||
| try: | ||||
|     import fast_depends.dependencies | ||||
| except ImportError: | ||||
|     fast_depends = None | ||||
| 
 | ||||
| 
 | ||||
| from . import providers | ||||
| 
 | ||||
| __all__ = ( | ||||
|  | @ -583,6 +589,8 @@ def _unpatch_attribute(patched: PatchedAttribute) -> None: | |||
| 
 | ||||
| 
 | ||||
| def _extract_marker(parameter: inspect.Parameter) -> Optional["_Marker"]: | ||||
|     depends_available = False | ||||
| 
 | ||||
|     if get_origin(parameter.annotation) is Annotated: | ||||
|         args = get_args(parameter.annotation) | ||||
|         if len(args) > 1: | ||||
|  | @ -592,10 +600,13 @@ def _extract_marker(parameter: inspect.Parameter) -> Optional["_Marker"]: | |||
|     else: | ||||
|         marker = parameter.default | ||||
| 
 | ||||
|     if not isinstance(marker, _Marker) and not _is_fastapi_depends(marker): | ||||
|     if _is_fastapi_depends(marker) or _is_fast_stream_depends(marker): | ||||
|         depends_available = True | ||||
| 
 | ||||
|     if not isinstance(marker, _Marker) and not depends_available: | ||||
|         return None | ||||
| 
 | ||||
|     if _is_fastapi_depends(marker): | ||||
|     if depends_available: | ||||
|         marker = marker.dependency | ||||
| 
 | ||||
|         if not isinstance(marker, _Marker): | ||||
|  | @ -721,6 +732,14 @@ def _is_fastapi_depends(param: Any) -> bool: | |||
|     return fastapi and isinstance(param, fastapi.params.Depends) | ||||
| 
 | ||||
| 
 | ||||
| if fast_depends: | ||||
|     def _is_fast_stream_depends(param: Any) -> bool: | ||||
|         return isinstance(param, fast_depends.dependencies.Depends) | ||||
| else: | ||||
|     def _is_fast_stream_depends(param: Any) -> bool: | ||||
|         return False | ||||
| 
 | ||||
| 
 | ||||
| def _is_patched(fn) -> bool: | ||||
|     return _patched_registry.has_callable(fn) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user