diff --git a/pyproject.toml b/pyproject.toml index c98f3d62cc..8b1f8e2d39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -146,7 +146,7 @@ disallow_incomplete_defs = true disallow_subclassing_any = true disallow_untyped_decorators = true disallow_untyped_defs = true -enable_error_code = ["unused-awaitable"] +enable_error_code = ["possibly-undefined", "unused-awaitable"] no_implicit_optional = true python_version = "3.11" strict_equality = true diff --git a/sentry_sdk/integrations/beam.py b/sentry_sdk/integrations/beam.py index 31f45f73de..81a1c4a39e 100644 --- a/sentry_sdk/integrations/beam.py +++ b/sentry_sdk/integrations/beam.py @@ -14,7 +14,7 @@ ) if TYPE_CHECKING: - from typing import Any, Callable, Iterator, TypeVar + from typing import Any, Callable, Iterator, NoReturn, TypeVar from sentry_sdk._types import ExcInfo @@ -141,7 +141,7 @@ def _capture_exception(exc_info: "ExcInfo") -> None: sentry_sdk.capture_event(event, hint=hint) -def raise_exception() -> None: +def raise_exception() -> "NoReturn": """ Raise an exception. """ diff --git a/sentry_sdk/integrations/chalice.py b/sentry_sdk/integrations/chalice.py index 9baa0e5cdd..cbda5e5ea6 100644 --- a/sentry_sdk/integrations/chalice.py +++ b/sentry_sdk/integrations/chalice.py @@ -161,13 +161,15 @@ def setup_once() -> None: raise DidNotEnable("Unparsable Chalice version: {}".format(CHALICE_VERSION)) if version < (1, 20): - old_get_view_function_response = Chalice._get_view_function_response + view_function_response_owner = Chalice else: from chalice.app import RestAPIEventHandler - old_get_view_function_response = ( - RestAPIEventHandler._get_view_function_response - ) + view_function_response_owner = RestAPIEventHandler + + old_get_view_function_response = ( + view_function_response_owner._get_view_function_response + ) def sentry_event_response( app: "Any", view_function: "F", function_args: "Dict[str, Any]" @@ -180,9 +182,6 @@ def sentry_event_response( app, wrapped_view_function, function_args ) - if version < (1, 20): - Chalice._get_view_function_response = sentry_event_response - else: - RestAPIEventHandler._get_view_function_response = sentry_event_response + view_function_response_owner._get_view_function_response = sentry_event_response # for everything else (like events) chalice.app.EventSourceHandler = EventSourceHandler diff --git a/sentry_sdk/integrations/grpc/aio/server.py b/sentry_sdk/integrations/grpc/aio/server.py index 15dcacab59..39956bb639 100644 --- a/sentry_sdk/integrations/grpc/aio/server.py +++ b/sentry_sdk/integrations/grpc/aio/server.py @@ -120,7 +120,7 @@ async def wrapped(request: "Any", context: "ServicerContext") -> "Any": response = handler.stream_unary(request, context) return await response - elif handler.request_streaming and handler.response_streaming: + else: handler_factory = grpc.stream_stream_rpc_method_handler async def wrapped(request: "Any", context: "ServicerContext") -> "Any": # type: ignore diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 78242ba92c..e9a1b4ca6e 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -984,8 +984,8 @@ def _get_request_data( ) tools = tools if tools and len(tools) > 0 else None + agent_name = None try: - agent_name = None if len(args) > 1: agent_name = args[1].get("run_name") if agent_name is None: diff --git a/sentry_sdk/integrations/litestar.py b/sentry_sdk/integrations/litestar.py index 612c4fbfe8..dbff6ee41f 100644 --- a/sentry_sdk/integrations/litestar.py +++ b/sentry_sdk/integrations/litestar.py @@ -298,6 +298,7 @@ async def handle_wrapper( route_handler = scope.get("route_handler") + name = None func = None if route_handler.name is not None: name = route_handler.name diff --git a/sentry_sdk/integrations/mcp.py b/sentry_sdk/integrations/mcp.py index 5fc186f505..0500e1bf3c 100644 --- a/sentry_sdk/integrations/mcp.py +++ b/sentry_sdk/integrations/mcp.py @@ -291,6 +291,7 @@ async def _tool_handler_wrapper( original_kwargs = original_kwargs or {} + handler_name = "unknown" if original_args: handler_name = original_args[0] elif original_kwargs.get("name"): @@ -521,6 +522,7 @@ async def _prompt_handler_wrapper( original_kwargs = original_kwargs or {} + handler_name = "unknown" if original_args: handler_name = original_args[0] elif original_kwargs.get("name"): diff --git a/sentry_sdk/integrations/quart.py b/sentry_sdk/integrations/quart.py index 0aa6dedfa4..0a7e2105fc 100644 --- a/sentry_sdk/integrations/quart.py +++ b/sentry_sdk/integrations/quart.py @@ -177,10 +177,12 @@ async def _request_websocket_started(app: "Quart", **kwargs: "Any") -> None: if integration is None: return - if has_request_context(): - request_websocket = request._get_current_object() if has_websocket_context(): request_websocket = websocket._get_current_object() + elif has_request_context(): + request_websocket = request._get_current_object() + else: + return route_path = None try: diff --git a/sentry_sdk/integrations/starlite.py b/sentry_sdk/integrations/starlite.py index 70a1540263..a6bec66dbd 100644 --- a/sentry_sdk/integrations/starlite.py +++ b/sentry_sdk/integrations/starlite.py @@ -246,6 +246,7 @@ async def handle_wrapper( route_handler = scope.get("route_handler") + name = None func = None if route_handler.name is not None: name = route_handler.name diff --git a/sentry_sdk/integrations/stdlib.py b/sentry_sdk/integrations/stdlib.py index c140b7b70c..395f3194c2 100644 --- a/sentry_sdk/integrations/stdlib.py +++ b/sentry_sdk/integrations/stdlib.py @@ -295,6 +295,7 @@ def putrequest( span_streaming = has_span_streaming_enabled(client.options) span: "Union[Span, StreamedSpan, None]" = None breadcrumb: "dict[str, Any]" = {} + set_on_span: "Optional[Callable[[str, Any], None]]" = None if span_streaming: url_attributes = get_url_attributes(client, parsed_url) @@ -361,7 +362,7 @@ def putrequest( # for proxies, these point to the proxy host/port if tunnel_host: - if span: + if set_on_span is not None: set_on_span(SPANDATA.NETWORK_PEER_ADDRESS, self.host) set_on_span(SPANDATA.NETWORK_PEER_PORT, self.port) diff --git a/sentry_sdk/spotlight.py b/sentry_sdk/spotlight.py index 93cf33be13..10589a1bc7 100644 --- a/sentry_sdk/spotlight.py +++ b/sentry_sdk/spotlight.py @@ -134,10 +134,10 @@ def __init__(self: "Self", get_response: "Callable[..., HttpResponse]") -> None: @property def spotlight_script(self: "Self") -> "Optional[str]": if self._spotlight_url is not None and self._spotlight_script is None: + spotlight_js_url = urllib.parse.urljoin( + self._spotlight_url, SPOTLIGHT_JS_ENTRY_PATH + ) try: - spotlight_js_url = urllib.parse.urljoin( - self._spotlight_url, SPOTLIGHT_JS_ENTRY_PATH - ) req = urllib.request.Request( spotlight_js_url, method="HEAD", diff --git a/sentry_sdk/transport.py b/sentry_sdk/transport.py index f459c87c01..ebaa542fcf 100644 --- a/sentry_sdk/transport.py +++ b/sentry_sdk/transport.py @@ -818,21 +818,17 @@ def _make_pool(self: "Self") -> "Union[PoolManager, ProxyManager]": opts["proxy_headers"] = proxy_headers if proxy.startswith("socks"): - use_socks_proxy = True try: # Check if PySocks dependency is available from urllib3.contrib.socks import SOCKSProxyManager except ImportError: - use_socks_proxy = False logger.warning( "You have configured a SOCKS proxy (%s) but support for SOCKS proxies is not installed. Disabling proxy support. Please add `PySocks` (or `urllib3` with the `[socks]` extra) to your dependencies.", proxy, ) - - if use_socks_proxy: - return SOCKSProxyManager(proxy, **opts) - else: return urllib3.PoolManager(**opts) + + return SOCKSProxyManager(proxy, **opts) else: return urllib3.ProxyManager(proxy, **opts) else: