From 8cc2c1188bc92f0eeaaa212641ae659723009f26 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Mon, 15 Feb 2021 17:47:03 -0500 Subject: [PATCH 1/2] Fix issue #398 with FastAPI request importing --- docs/main/changelog.rst | 6 ++++++ src/dependency_injector/wiring.py | 9 +++++++-- tests/unit/samples/wiringfastapi/web.py | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index 5ee2dc96..2cc585d0 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -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 +------------------- +- Hotfix a bug with importing FastAPI ``Request``. + See issue: `#398 `_. + Thanks to `@tapm `_ for reporting the bug. + 4.23.0 ------ - Add support of aliases for ``Configuration`` provider. diff --git a/src/dependency_injector/wiring.py b/src/dependency_injector/wiring.py index 81fa3985..205eee04 100644 --- a/src/dependency_injector/wiring.py +++ b/src/dependency_injector/wiring.py @@ -345,8 +345,13 @@ 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: + # Hotfix, see: + # - https://github.com/ets-labs/python-dependency-injector/issues/362 + # - https://github.com/ets-labs/python-dependency-injector/issues/398 + if GenericAlias and any(( + fn is GenericAlias, + getattr(fn, '__func__', None) is GenericAlias + )): fn = fn.__init__ signature = inspect.signature(fn) diff --git a/tests/unit/samples/wiringfastapi/web.py b/tests/unit/samples/wiringfastapi/web.py index 2e563d7d..2cbd4f50 100644 --- a/tests/unit/samples/wiringfastapi/web.py +++ b/tests/unit/samples/wiringfastapi/web.py @@ -1,6 +1,7 @@ import sys from fastapi import FastAPI, Depends +from fastapi import Request # See: https://github.com/ets-labs/python-dependency-injector/issues/398 from fastapi.security import HTTPBasic, HTTPBasicCredentials from dependency_injector import containers, providers from dependency_injector.wiring import inject, Provide From 12d53c799d2c69731ddc58a25f465eabfda8a142 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Mon, 15 Feb 2021 18:13:01 -0500 Subject: [PATCH 2/2] Bump version to 4.23.1 --- docs/main/changelog.rst | 4 ++-- src/dependency_injector/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index 2cc585d0..c6dca417 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -7,8 +7,8 @@ that were made in every particular version. From version 0.7.6 *Dependency Injector* framework strictly follows `Semantic versioning`_ -Development version -------------------- +4.23.1 +------ - Hotfix a bug with importing FastAPI ``Request``. See issue: `#398 `_. Thanks to `@tapm `_ for reporting the bug. diff --git a/src/dependency_injector/__init__.py b/src/dependency_injector/__init__.py index 6bb0c6ff..7900d9f0 100644 --- a/src/dependency_injector/__init__.py +++ b/src/dependency_injector/__init__.py @@ -1,6 +1,6 @@ """Top-level package.""" -__version__ = '4.23.0' +__version__ = '4.23.1' """Version number. :type: str