mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-10-31 16:07:51 +03:00 
			
		
		
		
	Add signature guards
This commit is contained in:
		
							parent
							
								
									b3bcf60ced
								
							
						
					
					
						commit
						677857f215
					
				|  | @ -10,5 +10,7 @@ pyyaml | ||||||
| httpx | httpx | ||||||
| fastapi | fastapi | ||||||
| pydantic | pydantic | ||||||
|  | numpy | ||||||
|  | scipy | ||||||
| 
 | 
 | ||||||
| -r requirements-ext.txt | -r requirements-ext.txt | ||||||
|  |  | ||||||
|  | @ -298,6 +298,8 @@ class InspectFilter: | ||||||
|             return True |             return True | ||||||
|         elif self._is_starlette_request_cls(instance): |         elif self._is_starlette_request_cls(instance): | ||||||
|             return True |             return True | ||||||
|  |         elif self._is_builtin(instance): | ||||||
|  |             return True | ||||||
|         else: |         else: | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|  | @ -309,6 +311,9 @@ class InspectFilter: | ||||||
|                and isinstance(instance, type) \ |                and isinstance(instance, type) \ | ||||||
|                and issubclass(instance, starlette.requests.Request) |                and issubclass(instance, starlette.requests.Request) | ||||||
| 
 | 
 | ||||||
|  |     def _is_builtin(self, instance: object) -> bool: | ||||||
|  |         return inspect.isbuiltin(instance) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| def wire(  # noqa: C901 | def wire(  # noqa: C901 | ||||||
|         container: Container, |         container: Container, | ||||||
|  | @ -488,7 +493,15 @@ def _fetch_reference_injections( | ||||||
|             )): |             )): | ||||||
|         fn = fn.__init__ |         fn = fn.__init__ | ||||||
| 
 | 
 | ||||||
|     signature = inspect.signature(fn) |     try: | ||||||
|  |         signature = inspect.signature(fn) | ||||||
|  |     except ValueError as exception: | ||||||
|  |         if 'no signature found' in str(exception): | ||||||
|  |             return {}, {} | ||||||
|  |         elif 'not supported by signature' in str(exception): | ||||||
|  |             return {}, {} | ||||||
|  |         else: | ||||||
|  |             raise exception | ||||||
| 
 | 
 | ||||||
|     injections = {} |     injections = {} | ||||||
|     closing = {} |     closing = {} | ||||||
|  | @ -874,9 +887,13 @@ class AutoLoader: | ||||||
|                 super().exec_module(module) |                 super().exec_module(module) | ||||||
|                 loader.wire_module(module) |                 loader.wire_module(module) | ||||||
| 
 | 
 | ||||||
|  |         class ExtensionFileLoader(importlib.machinery.ExtensionFileLoader): | ||||||
|  |             ... | ||||||
|  | 
 | ||||||
|         loader_details = [ |         loader_details = [ | ||||||
|             (SourcelessFileLoader, importlib.machinery.BYTECODE_SUFFIXES), |             (SourcelessFileLoader, importlib.machinery.BYTECODE_SUFFIXES), | ||||||
|             (SourceFileLoader, importlib.machinery.SOURCE_SUFFIXES), |             (SourceFileLoader, importlib.machinery.SOURCE_SUFFIXES), | ||||||
|  |             (ExtensionFileLoader, importlib.machinery.EXTENSION_SUFFIXES), | ||||||
|         ] |         ] | ||||||
| 
 | 
 | ||||||
|         self._path_hook = importlib.machinery.FileFinder.path_hook(*loader_details) |         self._path_hook = importlib.machinery.FileFinder.path_hook(*loader_details) | ||||||
|  |  | ||||||
|  | @ -128,3 +128,15 @@ def test_class_decorator(service: Service = Provide[Container.service]): | ||||||
| 
 | 
 | ||||||
| def test_container(container: Container = Provide[Container]): | def test_container(container: Container = Provide[Container]): | ||||||
|     return container.service() |     return container.service() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | # Import tests | ||||||
|  | 
 | ||||||
|  | import numpy  # noqa | ||||||
|  | from numpy import *  # noqa | ||||||
|  | 
 | ||||||
|  | import scipy  # noqa | ||||||
|  | from scipy import *  # noqa | ||||||
|  | 
 | ||||||
|  | import builtins  # noqa | ||||||
|  | from builtins import *  # noqa | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user