4040)
4141
4242if TYPE_CHECKING :
43- from typing import Any , Awaitable , Callable , Container , Dict , Optional , Tuple , Union
43+ from typing import (
44+ Any ,
45+ Awaitable ,
46+ Callable ,
47+ Container ,
48+ Dict ,
49+ Optional ,
50+ Tuple ,
51+ Union ,
52+ )
4453
4554 from sentry_sdk ._types import Event , HttpStatusCodeRange
46-
4755try :
48- import starlette # type: ignore
56+ import starlette
4957 from starlette import __version__ as STARLETTE_VERSION
50- from starlette .applications import Starlette # type: ignore
51- from starlette .datastructures import ( # type: ignore
58+ from starlette .applications import Starlette
59+ from starlette .datastructures import (
5260 UploadFile ,
5361 )
54- from starlette .middleware import Middleware # type: ignore
55- from starlette .middleware .authentication import ( # type: ignore
62+ from starlette .middleware import Middleware
63+ from starlette .middleware .authentication import (
5664 AuthenticationMiddleware ,
5765 )
58- from starlette .requests import Request # type: ignore
59- from starlette .routing import Match # type: ignore
60- from starlette .types import ASGIApp , Receive , Send # type: ignore
66+ from starlette .requests import Request
67+ from starlette .routing import Match
68+ from starlette .types import ASGIApp , Receive , Send
6169 from starlette .types import Scope as StarletteScope
6270except ImportError :
6371 raise DidNotEnable ("Starlette is not installed" )
6472
6573try :
6674 # Starlette 0.20
67- from starlette .middleware .exceptions import ExceptionMiddleware # type: ignore
75+ from starlette .middleware .exceptions import ExceptionMiddleware
6876except ImportError :
6977 # Startlette 0.19.1
7078 from starlette .exceptions import ExceptionMiddleware # type: ignore
@@ -156,8 +164,10 @@ def setup_once() -> None:
156164 patch_templates ()
157165
158166
159- def _enable_span_for_middleware (middleware_class : "Any" ) -> type :
160- old_call = middleware_class .__call__
167+ def _enable_span_for_middleware (
168+ middleware_class : "Any" ,
169+ ) -> "Any" :
170+ old_call : "Callable[..., Awaitable[Any]]" = middleware_class .__call__
161171
162172 async def _create_span_call (
163173 app : "Any" ,
@@ -430,7 +440,7 @@ def _sentry_middleware_init(
430440 if cls == ExceptionMiddleware :
431441 patch_exception_middleware (cls )
432442
433- Middleware .__init__ = _sentry_middleware_init
443+ Middleware .__init__ = _sentry_middleware_init # type: ignore[method-assign]
434444
435445
436446def patch_asgi_app (root_path_in_path : "_RootPathInPath" ) -> None :
@@ -462,7 +472,7 @@ async def _sentry_patched_asgi_app(
462472
463473 return await middleware (scope , receive , send )
464474
465- Starlette .__call__ = _sentry_patched_asgi_app
475+ Starlette .__call__ = _sentry_patched_asgi_app # type: ignore[method-assign]
466476
467477
468478# This was vendored in from Starlette to support Starlette 0.19.1 because
@@ -662,7 +672,7 @@ def patch_templates() -> None:
662672
663673 # https://github.com/Kludex/starlette/commit/96479daca2e4bd8157f68d914fd162aa94eff73a
664674 try :
665- from starlette .templating import Jinja2Templates # type: ignore
675+ from starlette .templating import Jinja2Templates
666676 except ImportError :
667677 return
668678
@@ -692,7 +702,7 @@ def add_sentry_trace_meta(request: "Request") -> "Dict[str, Any]":
692702
693703 return old_jinja2templates_init (self , * args , ** kwargs )
694704
695- Jinja2Templates .__init__ = _sentry_jinja2templates_init
705+ Jinja2Templates .__init__ = _sentry_jinja2templates_init # type: ignore[method-assign]
696706
697707
698708class StarletteRequestExtractor :
@@ -701,8 +711,6 @@ class StarletteRequestExtractor:
701711 (like form data or cookies) and adds it to the Sentry event.
702712 """
703713
704- request : "Request" = None
705-
706714 def __init__ (self : "StarletteRequestExtractor" , request : "Request" ) -> None :
707715 self .request = request
708716
0 commit comments