1616from contextlib import contextmanager
1717from importlib import import_module
1818from re import escape , sub
19- from typing import Dict , Iterable , Sequence , Union
19+ from typing import Any , Dict , Generator , Sequence
2020
2121from wrapt import ObjectProxy
2222
4444
4545
4646def extract_attributes_from_object (
47- obj : any , attributes : Sequence [str ], existing : Dict [str , str ] = None
47+ obj : Any , attributes : Sequence [str ], existing : Dict [str , str ] | None = None
4848) -> Dict [str , str ]:
49- extracted = {}
49+ extracted : dict [ str , str ] = {}
5050 if existing :
5151 extracted .update (existing )
5252 for attr in attributes :
@@ -81,7 +81,7 @@ def http_status_to_status_code(
8181 return StatusCode .ERROR
8282
8383
84- def unwrap (obj : Union [ object , str ] , attr : str ):
84+ def unwrap (obj : object , attr : str ):
8585 """Given a function that was wrapped by wrapt.wrap_function_wrapper, unwrap it
8686
8787 The object containing the function to unwrap may be passed as dotted module path string.
@@ -152,7 +152,7 @@ def _start_internal_or_server_span(
152152 return span , token
153153
154154
155- def _url_quote (s ) -> str : # pylint: disable=invalid-name
155+ def _url_quote (s : Any ) -> str : # pylint: disable=invalid-name
156156 if not isinstance (s , (str , bytes )):
157157 return s
158158 quoted = urllib .parse .quote (s )
@@ -163,13 +163,13 @@ def _url_quote(s) -> str: # pylint: disable=invalid-name
163163 return quoted .replace ("%" , "%%" )
164164
165165
166- def _get_opentelemetry_values () -> dict :
166+ def _get_opentelemetry_values () -> dict [ str , Any ] :
167167 """
168168 Return the OpenTelemetry Trace and Span IDs if Span ID is set in the
169169 OpenTelemetry execution context.
170170 """
171171 # Insert the W3C TraceContext generated
172- _headers = {}
172+ _headers : dict [ str , Any ] = {}
173173 propagator .inject (_headers )
174174 return _headers
175175
@@ -196,7 +196,7 @@ def is_http_instrumentation_enabled() -> bool:
196196
197197
198198@contextmanager
199- def _suppress_instrumentation (* keys : str ) -> Iterable [None ]:
199+ def _suppress_instrumentation (* keys : str ) -> Generator [None ]:
200200 """Suppress instrumentation within the context."""
201201 ctx = context .get_current ()
202202 for key in keys :
@@ -209,7 +209,7 @@ def _suppress_instrumentation(*keys: str) -> Iterable[None]:
209209
210210
211211@contextmanager
212- def suppress_instrumentation () -> Iterable [None ]:
212+ def suppress_instrumentation () -> Generator [None ]:
213213 """Suppress instrumentation within the context."""
214214 with _suppress_instrumentation (
215215 _SUPPRESS_INSTRUMENTATION_KEY , _SUPPRESS_INSTRUMENTATION_KEY_PLAIN
@@ -218,7 +218,7 @@ def suppress_instrumentation() -> Iterable[None]:
218218
219219
220220@contextmanager
221- def suppress_http_instrumentation () -> Iterable [None ]:
221+ def suppress_http_instrumentation () -> Generator [None ]:
222222 """Suppress instrumentation within the context."""
223223 with _suppress_instrumentation (_SUPPRESS_HTTP_INSTRUMENTATION_KEY ):
224224 yield
0 commit comments