Skip to content

numpy.typing.NDArray breaks wiring #569

Closed
@VKFisher

Description

@VKFisher

Attempting to wire a module that imports NDArray from numpy.typing breaks wiring with the following error:

Traceback (most recent call last):
  File "/app/experiment.py", line 23, in <module>
    initialize()
  File "/app/framework/startup.py", line 9, in initialize
    container.wire(packages=[core])
  File "src/dependency_injector/containers.pyx", line 317, in dependency_injector.containers.DynamicContainer.wire
  File "/venv/lib/python3.9/site-packages/dependency_injector/wiring.py", line 350, in wire
    if _inspect_filter.is_excluded(member):
  File "/venv/lib/python3.9/site-packages/dependency_injector/wiring.py", line 311, in is_excluded
    elif self._is_starlette_request_cls(instance):
  File "/venv/lib/python3.9/site-packages/dependency_injector/wiring.py", line 324, in _is_starlette_request_cls
    and issubclass(instance, starlette.requests.Request)
  File "/usr/lib/python3.9/abc.py", line 123, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class

The problem occurs in this bit of code in wiring.py, specifically in the _is_starlette_request_cls method

class InspectFilter:

    def is_excluded(self, instance: object) -> bool:
        if self._is_werkzeug_local_proxy(instance):
            return True
        elif self._is_starlette_request_cls(instance):
            return True
        elif self._is_builtin(instance):
            return True
        else:
            return False

    def _is_werkzeug_local_proxy(self, instance: object) -> bool:
        return werkzeug and isinstance(instance, werkzeug.local.LocalProxy)

    def _is_starlette_request_cls(self, instance: object) -> bool:
        return starlette \
               and isinstance(instance, type) \
               and issubclass(instance, starlette.requests.Request)

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

Seems like NDArray passes the isinstance(instance, type) check, but then raises a TypeError when passed to issubclass

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions