Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/main/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_

Development version
-------------------
- Fix wiring to not crash on missing signatures.
See issue: `#420 <https://github.com/ets-labs/python-dependency-injector/issues/420>`_.
Thanks to `@Balthus1989 <https://github.com/Balthus1989>`_ for reporting the issue.

4.29.1
------
- Fix recursive copying issue in ``Delegate`` provider.
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ pyyaml
httpx
fastapi
pydantic
numpy
scipy

-r requirements-ext.txt
21 changes: 19 additions & 2 deletions src/dependency_injector/wiring.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ def is_excluded(self, instance: object) -> bool:
return True
elif self._is_starlette_request_cls(instance):
return True
elif self._is_builtin(instance):
return True
else:
return False

Expand All @@ -309,6 +311,9 @@ def _is_starlette_request_cls(self, instance: object) -> bool:
and isinstance(instance, type) \
and issubclass(instance, starlette.requests.Request)

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


def wire( # noqa: C901
container: Container,
Expand Down Expand Up @@ -476,7 +481,7 @@ def _unpatch_attribute(patched: PatchedAttribute) -> None:
setattr(patched.member, patched.name, patched.marker)


def _fetch_reference_injections(
def _fetch_reference_injections( # noqa: C901
fn: Callable[..., Any],
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
# Hotfix, see:
Expand All @@ -488,7 +493,15 @@ def _fetch_reference_injections(
)):
fn = fn.__init__

signature = inspect.signature(fn)
try:
signature = inspect.signature(fn)
except ValueError as exception:
if 'no signature found' in str(exception):
return {}, {}
elif 'not supported by signature' in str(exception):
return {}, {}
else:
raise exception

injections = {}
closing = {}
Expand Down Expand Up @@ -874,9 +887,13 @@ def exec_module(self, module):
super().exec_module(module)
loader.wire_module(module)

class ExtensionFileLoader(importlib.machinery.ExtensionFileLoader):
...

loader_details = [
(SourcelessFileLoader, importlib.machinery.BYTECODE_SUFFIXES),
(SourceFileLoader, importlib.machinery.SOURCE_SUFFIXES),
(ExtensionFileLoader, importlib.machinery.EXTENSION_SUFFIXES),
]

self._path_hook = importlib.machinery.FileFinder.path_hook(*loader_details)
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/samples/wiringsamples/module.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test module for wiring."""

from decimal import Decimal
import sys
from typing import Callable

from dependency_injector import providers
Expand Down Expand Up @@ -128,3 +129,16 @@ def test_class_decorator(service: Service = Provide[Container.service]):

def test_container(container: Container = Provide[Container]):
return container.service()


# Import tests

if 'pypy' not in sys.version.lower():
import numpy # noqa
from numpy import * # noqa

import scipy # noqa
from scipy import * # noqa

import builtins # noqa
from builtins import * # noqa
13 changes: 13 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ deps=
typing_extensions
httpx
fastapi
numpy
scipy
extras=
yaml
pydantic
Expand Down Expand Up @@ -62,6 +64,17 @@ extras=
commands=
python -m unittest discover -s tests/unit -p test_*_py2_py3.py

[testenv:pypy3]
deps=
httpx
fastapi
extras=
yaml
flask
commands=
python -m unittest discover -s tests/unit -p test_*_py2_py3.py


[testenv:pylint]
deps=
pylint
Expand Down