mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-04-01 07:44:26 +03:00
Add signature guards
This commit is contained in:
parent
b3bcf60ced
commit
677857f215
|
@ -10,5 +10,7 @@ pyyaml
|
|||
httpx
|
||||
fastapi
|
||||
pydantic
|
||||
numpy
|
||||
scipy
|
||||
|
||||
-r requirements-ext.txt
|
||||
|
|
|
@ -298,6 +298,8 @@ class InspectFilter:
|
|||
return True
|
||||
elif self._is_starlette_request_cls(instance):
|
||||
return True
|
||||
elif self._is_builtin(instance):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
@ -309,6 +311,9 @@ class InspectFilter:
|
|||
and isinstance(instance, type) \
|
||||
and issubclass(instance, starlette.requests.Request)
|
||||
|
||||
def _is_builtin(self, instance: object) -> bool:
|
||||
return inspect.isbuiltin(instance)
|
||||
|
||||
|
||||
def wire( # noqa: C901
|
||||
container: Container,
|
||||
|
@ -488,7 +493,15 @@ def _fetch_reference_injections(
|
|||
)):
|
||||
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 = {}
|
||||
closing = {}
|
||||
|
@ -874,9 +887,13 @@ class AutoLoader:
|
|||
super().exec_module(module)
|
||||
loader.wire_module(module)
|
||||
|
||||
class ExtensionFileLoader(importlib.machinery.ExtensionFileLoader):
|
||||
...
|
||||
|
||||
loader_details = [
|
||||
(SourcelessFileLoader, importlib.machinery.BYTECODE_SUFFIXES),
|
||||
(SourceFileLoader, importlib.machinery.SOURCE_SUFFIXES),
|
||||
(ExtensionFileLoader, importlib.machinery.EXTENSION_SUFFIXES),
|
||||
]
|
||||
|
||||
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]):
|
||||
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