From 5daa64284c6ce61aeb2d280362c120c911fb2a2a Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Sat, 27 Feb 2021 09:41:53 -0500 Subject: [PATCH] Upgrade exclusion filter --- src/dependency_injector/wiring.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/dependency_injector/wiring.py b/src/dependency_injector/wiring.py index b3919efc..54c90534 100644 --- a/src/dependency_injector/wiring.py +++ b/src/dependency_injector/wiring.py @@ -42,6 +42,12 @@ except ImportError: fastapi = None +try: + import starlette.requests +except ImportError: + starlette = None + + try: import werkzeug.local except ImportError: @@ -257,7 +263,7 @@ class InspectFilter: def is_excluded(self, instance: object) -> bool: if self._is_werkzeug_local_proxy(instance): return True - elif self._is_fastapi_request(instance): + elif self._is_starlette_request_cls(instance): return True else: return False @@ -265,8 +271,10 @@ class InspectFilter: def _is_werkzeug_local_proxy(self, instance: object) -> bool: return werkzeug and isinstance(instance, werkzeug.local.LocalProxy) - def _is_fastapi_request(self, instance: object) -> bool: - return fastapi and isinstance(instance, fastapi.Request) + def _is_starlette_request_cls(self, instance: object) -> bool: + return starlette \ + and isinstance(instance, type) \ + and issubclass(instance, starlette.requests.Request) inspect_filter = InspectFilter()