Skip to content

Commit 5daa642

Browse files
committed
Upgrade exclusion filter
1 parent 75e346c commit 5daa642

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/dependency_injector/wiring.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class GenericMeta(type):
4242
fastapi = None
4343

4444

45+
try:
46+
import starlette.requests
47+
except ImportError:
48+
starlette = None
49+
50+
4551
try:
4652
import werkzeug.local
4753
except ImportError:
@@ -257,16 +263,18 @@ class InspectFilter:
257263
def is_excluded(self, instance: object) -> bool:
258264
if self._is_werkzeug_local_proxy(instance):
259265
return True
260-
elif self._is_fastapi_request(instance):
266+
elif self._is_starlette_request_cls(instance):
261267
return True
262268
else:
263269
return False
264270

265271
def _is_werkzeug_local_proxy(self, instance: object) -> bool:
266272
return werkzeug and isinstance(instance, werkzeug.local.LocalProxy)
267273

268-
def _is_fastapi_request(self, instance: object) -> bool:
269-
return fastapi and isinstance(instance, fastapi.Request)
274+
def _is_starlette_request_cls(self, instance: object) -> bool:
275+
return starlette \
276+
and isinstance(instance, type) \
277+
and issubclass(instance, starlette.requests.Request)
270278

271279

272280
inspect_filter = InspectFilter()

0 commit comments

Comments
 (0)