diff --git a/src/dependency_injector/wiring.py b/src/dependency_injector/wiring.py index 927796bc..42882533 100644 --- a/src/dependency_injector/wiring.py +++ b/src/dependency_injector/wiring.py @@ -321,13 +321,7 @@ class InspectFilter: def _is_starlette_request_cls(self, instance: object) -> bool: return starlette \ and isinstance(instance, type) \ - 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 + and _safe_is_subclass(instance, starlette.requests.Request) def _is_builtin(self, instance: object) -> bool: return inspect.isbuiltin(instance) @@ -685,6 +679,13 @@ def _is_declarative_container(instance: Any) -> bool: and getattr(instance, "declarative_parent", None) is None) +def _safe_is_subclass(instance: Any, cls: Type) -> bool: + try: + return issubclass(instance, cls) + except TypeError: + return False + + class Modifier: def modify( diff --git a/tests/unit/samples/wiring/imports.py b/tests/unit/samples/wiring/imports.py index ecab7ce8..7416bb91 100644 --- a/tests/unit/samples/wiring/imports.py +++ b/tests/unit/samples/wiring/imports.py @@ -5,7 +5,8 @@ import sys if "pypy" not in sys.version.lower(): import numpy # noqa from numpy import * # noqa - from numpy.typing import * # noqa + if sys.version_info >= (3, 7): + from numpy.typing import * # noqa import scipy # noqa from scipy import * # noqa