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