From 8fe00bcff05f7a0e8939ab8e3adf54af9399f29c Mon Sep 17 00:00:00 2001 From: Vlad Fisher <51226323+VKFisher@users.noreply.github.com> Date: Mon, 28 Mar 2022 01:11:04 +0700 Subject: [PATCH] 569 fix numpy typing wiring (#570) * change erroneous issubclass call to isinstance * import numpy.typing in tests * better subclass check * fix return --- src/dependency_injector/wiring.py | 8 +++++++- tests/unit/samples/wiring/imports.py | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) 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