diff --git a/src/dependency_injector/wiring.py b/src/dependency_injector/wiring.py index 37aba496..927796bc 100644 --- a/src/dependency_injector/wiring.py +++ b/src/dependency_injector/wiring.py @@ -321,7 +321,13 @@ class InspectFilter: def _is_starlette_request_cls(self, instance: object) -> bool: return starlette \ and isinstance(instance, type) \ - and issubclass(instance, starlette.requests.Request) + and self._safe_is_subclass(instance, starlette.requests.Request) + + def _safe_is_subclass(self, instance: type, cls: type) -> bool: + try: + return issubclass(instance, cls) + except TypeError: + return False def _is_builtin(self, instance: object) -> bool: return inspect.isbuiltin(instance) diff --git a/tests/unit/samples/wiring/imports.py b/tests/unit/samples/wiring/imports.py index 37fa8ebe..ecab7ce8 100644 --- a/tests/unit/samples/wiring/imports.py +++ b/tests/unit/samples/wiring/imports.py @@ -5,6 +5,7 @@ import sys if "pypy" not in sys.version.lower(): import numpy # noqa from numpy import * # noqa + from numpy.typing import * # noqa import scipy # noqa from scipy import * # noqa