mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-10-31 07:57:43 +03:00 
			
		
		
		
	Fix: robust Annotated detection for wiring across Python versions
This commit is contained in:
		
							parent
							
								
									c2619cc43f
								
							
						
					
					
						commit
						164a45cd82
					
				|  | @ -578,8 +578,13 @@ def _unpatch_attribute(patched: PatchedAttribute) -> None: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def _extract_marker(parameter: inspect.Parameter) -> Optional["_Marker"]: | def _extract_marker(parameter: inspect.Parameter) -> Optional["_Marker"]: | ||||||
|     if get_origin(parameter.annotation) is Annotated: |     is_annotated = ( | ||||||
|         marker = get_args(parameter.annotation)[1] |         isinstance(annotation, type(Annotated)) | ||||||
|  |         and get_origin(annotation) is not None | ||||||
|  |         and get_origin(annotation) is get_origin(Annotated) | ||||||
|  |     ) | ||||||
|  |     if is_annotated: | ||||||
|  |         marker = get_args(annotation)[1] | ||||||
|     else: |     else: | ||||||
|         marker = parameter.default |         marker = parameter.default | ||||||
| 
 | 
 | ||||||
|  | @ -1034,7 +1039,12 @@ def _get_members_and_annotated(obj: Any) -> Iterable[Tuple[str, Any]]: | ||||||
|     except Exception: |     except Exception: | ||||||
|         annotations = {} |         annotations = {} | ||||||
|     for annotation_name, annotation in annotations.items(): |     for annotation_name, annotation in annotations.items(): | ||||||
|         if get_origin(annotation) is Annotated: |         is_annotated = ( | ||||||
|  |             isinstance(annotation, type(Annotated)) | ||||||
|  |             and get_origin(annotation) is not None | ||||||
|  |             and get_origin(annotation) is get_origin(Annotated) | ||||||
|  |         ) | ||||||
|  |         if is_annotated: | ||||||
|             args = get_args(annotation) |             args = get_args(annotation) | ||||||
|             if len(args) > 1: |             if len(args) > 1: | ||||||
|                 member = args[1] |                 member = args[1] | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user