Skip to content

singledispatchmethod + classmethod causes .wire method to crash #950

@ScriptHound

Description

@ScriptHound

Version: dependency-injector==4.48.2, Python version: 3.11.14

My project has the following structure:

/

  • http
    • api.py
  • other_module
    • dependencies.py
  • schemas
    • my_schemas.py
      main.py

I want to wire things that are inside api.py and dependencies and for some reason python-dependency-injector tries to inspect my_schemas.py where I have a model like this:

class MyModel(BaseModel):
    field: int

    @classmethod
    @singledispatchmethod
    def model_validate(cls, param: ParamClass):
        ...
  File "/root/.venv/lib/python3.11/site-packages/dependency_injector/wiring.py", line 493, in wire
    _patch_method(
  File "/root/.venv/lib/python3.11/site-packages/dependency_injector/wiring.py", line 599, in _patch_method
    reference_injections, reference_closing = _fetch_reference_injections(fn)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.venv/lib/python3.11/site-packages/dependency_injector/wiring.py", line 707, in _fetch_reference_injections
    signature = inspect.signature(fn)
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/inspect.py", line 3263, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/inspect.py", line 3011, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/inspect.py", line 2456, in _signature_from_callable
    raise TypeError('{!r} is not a callable object'.format(obj))

TypeError: <functools.singledispatchmethod object at 0x7f7c7489a050> is not a callable object

Is there any way to tell python-dependency-injector to not inspect certain classes or methods? I theres no such functionality I can try add that or fix the bug

P.S. dont ask me why am I using singledispatchmethod please

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions