Skip to content

Commit 8fe00bc

Browse files
authored
569 fix numpy typing wiring (ets-labs#570)
* change erroneous issubclass call to isinstance * import numpy.typing in tests * better subclass check * fix return
1 parent c26b260 commit 8fe00bc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/dependency_injector/wiring.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,13 @@ def _is_werkzeug_local_proxy(self, instance: object) -> bool:
321321
def _is_starlette_request_cls(self, instance: object) -> bool:
322322
return starlette \
323323
and isinstance(instance, type) \
324-
and issubclass(instance, starlette.requests.Request)
324+
and self._safe_is_subclass(instance, starlette.requests.Request)
325+
326+
def _safe_is_subclass(self, instance: type, cls: type) -> bool:
327+
try:
328+
return issubclass(instance, cls)
329+
except TypeError:
330+
return False
325331

326332
def _is_builtin(self, instance: object) -> bool:
327333
return inspect.isbuiltin(instance)

tests/unit/samples/wiring/imports.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
if "pypy" not in sys.version.lower():
66
import numpy # noqa
77
from numpy import * # noqa
8+
from numpy.typing import * # noqa
89

910
import scipy # noqa
1011
from scipy import * # noqa

0 commit comments

Comments
 (0)