diff --git a/.travis.yml b/.travis.yml index b1b6966a..075c6be1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ dist: xenial language: python jobs: include: - - python: 3.8 + - python: 3.9 env: TOXENV=coveralls DEPENDENCY_INJECTOR_DEBUG_MODE=1 install: - pip install tox diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index 6f7fe075..3eea996a 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -7,6 +7,15 @@ that were made in every particular version. From version 0.7.6 *Dependency Injector* framework strictly follows `Semantic versioning`_ +4.10.1 +------ +- Fix a Python 3.9 specific bug in ``wiring`` module: introspection doesn't work for + builtin ``types.GenericAlias``. This resulted in wiring failure for modules + importing ``queue.Queue``. + See issue `#362 `_. + Thanks `@ventaquil `_ for the bug report. +- Switch Coveralls reporting Travis Job to run on Python 3.9. + 4.10.0 ------ - Add ``strict`` mode and ``required`` modifier for ``Configuration`` provider. diff --git a/src/dependency_injector/__init__.py b/src/dependency_injector/__init__.py index d290f2a9..f6579f90 100644 --- a/src/dependency_injector/__init__.py +++ b/src/dependency_injector/__init__.py @@ -1,6 +1,6 @@ """Top-level package.""" -__version__ = '4.10.0' +__version__ = '4.10.1' """Version number. :type: str diff --git a/src/dependency_injector/wiring.py b/src/dependency_injector/wiring.py index 9318b654..c738bf02 100644 --- a/src/dependency_injector/wiring.py +++ b/src/dependency_injector/wiring.py @@ -28,6 +28,12 @@ else: class GenericMeta(type): ... +# Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/362 +if sys.version_info >= (3, 9): + from types import GenericAlias +else: + GenericAlias = None + try: from fastapi.params import Depends as FastAPIDepends @@ -333,6 +339,10 @@ def _unpatch( def _fetch_reference_injections( fn: Callable[..., Any], ) -> Tuple[Dict[str, Any], Dict[str, Any]]: + # # Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/362 + if GenericAlias and fn is GenericAlias: + fn = fn.__init__ + signature = inspect.signature(fn) injections = {} diff --git a/tests/unit/samples/wiringsamples/queuemodule.py b/tests/unit/samples/wiringsamples/queuemodule.py new file mode 100644 index 00000000..5849a7bd --- /dev/null +++ b/tests/unit/samples/wiringsamples/queuemodule.py @@ -0,0 +1,5 @@ +# Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/362 +from queue import Queue + + +__all__ = ('Queue',) diff --git a/tests/unit/wiring/test_wiring_py36.py b/tests/unit/wiring/test_wiring_py36.py index 1972b8bc..84938a6a 100644 --- a/tests/unit/wiring/test_wiring_py36.py +++ b/tests/unit/wiring/test_wiring_py36.py @@ -263,6 +263,21 @@ class WiringTest(unittest.TestCase): self.assertIsInstance(service, Service) +class WiringAndQueue(unittest.TestCase): + + def test_wire_queue(self) -> None: + from wiringsamples import queuemodule + container = Container() + self.addCleanup(container.unwire) + + # Should not raise exception + # See: https://github.com/ets-labs/python-dependency-injector/issues/362 + try: + container.wire(modules=[queuemodule]) + except: + raise + + class WiringAndFastAPITest(unittest.TestCase): container: Container diff --git a/tox.ini b/tox.ini index bb6417f0..ddc458ec 100644 --- a/tox.ini +++ b/tox.ini @@ -18,7 +18,7 @@ commands= [testenv:coveralls] passenv=TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH DEPENDENCY_INJECTOR_DEBUG_MODE -basepython=python3.8 +basepython=python3.9 usedevelop=True deps= {[testenv]deps}