diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7e2812bc54..775167c10f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: - id: end-of-file-fixer - repo: https://github.com/psf/black - rev: 22.6.0 + rev: 24.1.0 hooks: - id: black exclude: ^(.*_pb2.py|.*_pb2_grpc.py) diff --git a/sentry_sdk/integrations/arq.py b/sentry_sdk/integrations/arq.py index f46d1204c5..ed045b854a 100644 --- a/sentry_sdk/integrations/arq.py +++ b/sentry_sdk/integrations/arq.py @@ -149,12 +149,12 @@ def event_processor(event, hint): extra = event.setdefault("extra", {}) extra["arq-job"] = { "task": ctx["job_name"], - "args": args - if _should_send_default_pii() - else SENSITIVE_DATA_SUBSTITUTE, - "kwargs": kwargs - if _should_send_default_pii() - else SENSITIVE_DATA_SUBSTITUTE, + "args": ( + args if _should_send_default_pii() else SENSITIVE_DATA_SUBSTITUTE + ), + "kwargs": ( + kwargs if _should_send_default_pii() else SENSITIVE_DATA_SUBSTITUTE + ), "retry": ctx["job_try"], } diff --git a/sentry_sdk/integrations/huey.py b/sentry_sdk/integrations/huey.py index 52b0e549a2..9641160099 100644 --- a/sentry_sdk/integrations/huey.py +++ b/sentry_sdk/integrations/huey.py @@ -73,12 +73,16 @@ def event_processor(event, hint): extra = event.setdefault("extra", {}) extra["huey-job"] = { "task": task.name, - "args": task.args - if _should_send_default_pii() - else SENSITIVE_DATA_SUBSTITUTE, - "kwargs": task.kwargs - if _should_send_default_pii() - else SENSITIVE_DATA_SUBSTITUTE, + "args": ( + task.args + if _should_send_default_pii() + else SENSITIVE_DATA_SUBSTITUTE + ), + "kwargs": ( + task.kwargs + if _should_send_default_pii() + else SENSITIVE_DATA_SUBSTITUTE + ), "retry": (task.default_retries or 0) - task.retries, } diff --git a/sentry_sdk/integrations/opentelemetry/integration.py b/sentry_sdk/integrations/opentelemetry/integration.py index e1a4318f67..9e62d1feca 100644 --- a/sentry_sdk/integrations/opentelemetry/integration.py +++ b/sentry_sdk/integrations/opentelemetry/integration.py @@ -3,6 +3,7 @@ are experimental and not suitable for production use. They may be changed or removed at any time without prior notice. """ + import sys from importlib import import_module diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 7678def407..b0dcca8b15 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -270,9 +270,9 @@ def get_dynamic_sampling_context(self): baggage = self.get_baggage() if baggage is not None: - self._propagation_context[ - "dynamic_sampling_context" - ] = baggage.dynamic_sampling_context() + self._propagation_context["dynamic_sampling_context"] = ( + baggage.dynamic_sampling_context() + ) return self._propagation_context["dynamic_sampling_context"] diff --git a/sentry_sdk/serializer.py b/sentry_sdk/serializer.py index 7925cf5ec8..51496f57ce 100644 --- a/sentry_sdk/serializer.py +++ b/sentry_sdk/serializer.py @@ -348,9 +348,9 @@ def _serialize_node_impl( should_repr_strings=should_repr_strings, is_databag=is_databag, is_request_body=is_request_body, - remaining_depth=remaining_depth - 1 - if remaining_depth is not None - else None, + remaining_depth=( + remaining_depth - 1 if remaining_depth is not None else None + ), remaining_breadth=remaining_breadth, ) rv_dict[str_k] = v @@ -375,9 +375,9 @@ def _serialize_node_impl( should_repr_strings=should_repr_strings, is_databag=is_databag, is_request_body=is_request_body, - remaining_depth=remaining_depth - 1 - if remaining_depth is not None - else None, + remaining_depth=( + remaining_depth - 1 if remaining_depth is not None else None + ), remaining_breadth=remaining_breadth, ) ) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 82ec994e14..80e9ace939 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -544,9 +544,9 @@ def get_trace_context(self): rv["status"] = self.status if self.containing_transaction: - rv[ - "dynamic_sampling_context" - ] = self.containing_transaction.get_baggage().dynamic_sampling_context() + rv["dynamic_sampling_context"] = ( + self.containing_transaction.get_baggage().dynamic_sampling_context() + ) return rv diff --git a/tests/integrations/asyncpg/test_asyncpg.py b/tests/integrations/asyncpg/test_asyncpg.py index 9177d68bdf..2a31c59dee 100644 --- a/tests/integrations/asyncpg/test_asyncpg.py +++ b/tests/integrations/asyncpg/test_asyncpg.py @@ -8,6 +8,7 @@ The tests use the following credentials to establish a database connection. """ + import os diff --git a/tests/integrations/aws_lambda/client.py b/tests/integrations/aws_lambda/client.py index 3c4816a477..298ebd920d 100644 --- a/tests/integrations/aws_lambda/client.py +++ b/tests/integrations/aws_lambda/client.py @@ -386,12 +386,14 @@ def repl(runtime, verbose): _REPL_CODE.format(line=line), b"", cleanup.append, - subprocess_kwargs={ - "stdout": subprocess.DEVNULL, - "stderr": subprocess.DEVNULL, - } - if not verbose - else {}, + subprocess_kwargs=( + { + "stdout": subprocess.DEVNULL, + "stderr": subprocess.DEVNULL, + } + if not verbose + else {} + ), ) for line in base64.b64decode(response["LogResult"]).splitlines(): diff --git a/tests/integrations/clickhouse_driver/test_clickhouse_driver.py b/tests/integrations/clickhouse_driver/test_clickhouse_driver.py index 6b0fa566d4..74a04fac44 100644 --- a/tests/integrations/clickhouse_driver/test_clickhouse_driver.py +++ b/tests/integrations/clickhouse_driver/test_clickhouse_driver.py @@ -4,6 +4,7 @@ docker run -d -p 18123:8123 -p9000:9000 --name clickhouse-test --ulimit nofile=262144:262144 --rm clickhouse/clickhouse-server ``` """ + import clickhouse_driver from clickhouse_driver import Client, connect diff --git a/tests/integrations/django/myapp/custom_urls.py b/tests/integrations/django/myapp/custom_urls.py index 6dfa2ed2f1..bc703e0afe 100644 --- a/tests/integrations/django/myapp/custom_urls.py +++ b/tests/integrations/django/myapp/custom_urls.py @@ -13,6 +13,7 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + from __future__ import absolute_import try: diff --git a/tests/integrations/django/myapp/settings.py b/tests/integrations/django/myapp/settings.py index b8b083eb81..ac06d9204e 100644 --- a/tests/integrations/django/myapp/settings.py +++ b/tests/integrations/django/myapp/settings.py @@ -10,7 +10,6 @@ https://docs.djangoproject.com/en/2.0/ref/settings/ """ - # We shouldn't access settings while setting up integrations. Initialize SDK # here to provoke any errors that might occur. import sentry_sdk diff --git a/tests/integrations/django/myapp/urls.py b/tests/integrations/django/myapp/urls.py index 0a62e4a076..706be13c3a 100644 --- a/tests/integrations/django/myapp/urls.py +++ b/tests/integrations/django/myapp/urls.py @@ -13,6 +13,7 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + from __future__ import absolute_import try: diff --git a/tests/integrations/gcp/test_gcp.py b/tests/integrations/gcp/test_gcp.py index 678219dc8b..9c4e11e8d5 100644 --- a/tests/integrations/gcp/test_gcp.py +++ b/tests/integrations/gcp/test_gcp.py @@ -2,6 +2,7 @@ # GCP Cloud Functions unit tests """ + import json from textwrap import dedent import tempfile diff --git a/tests/integrations/starlette/test_starlette.py b/tests/integrations/starlette/test_starlette.py index 329048e23c..202f8b53de 100644 --- a/tests/integrations/starlette/test_starlette.py +++ b/tests/integrations/starlette/test_starlette.py @@ -779,9 +779,11 @@ def test_middleware_partial_receive_send(sentry_init, capture_events): }, { "op": "middleware.starlette.receive", - "description": "_ASGIAdapter.send..receive" - if STARLETTE_VERSION < (0, 21) - else "_TestClientTransport.handle_request..receive", + "description": ( + "_ASGIAdapter.send..receive" + if STARLETTE_VERSION < (0, 21) + else "_TestClientTransport.handle_request..receive" + ), "tags": {"starlette.middleware_name": "ServerErrorMiddleware"}, }, { diff --git a/tests/test_profiler.py b/tests/test_profiler.py index 866349792a..9c38433800 100644 --- a/tests/test_profiler.py +++ b/tests/test_profiler.py @@ -393,9 +393,11 @@ def static_method(): ), pytest.param( GetFrame().instance_method_wrapped()(), - "wrapped" - if sys.version_info < (3, 11) - else "GetFrame.instance_method_wrapped..wrapped", + ( + "wrapped" + if sys.version_info < (3, 11) + else "GetFrame.instance_method_wrapped..wrapped" + ), id="instance_method_wrapped", ), pytest.param( @@ -405,9 +407,11 @@ def static_method(): ), pytest.param( GetFrame().class_method_wrapped()(), - "wrapped" - if sys.version_info < (3, 11) - else "GetFrame.class_method_wrapped..wrapped", + ( + "wrapped" + if sys.version_info < (3, 11) + else "GetFrame.class_method_wrapped..wrapped" + ), id="class_method_wrapped", ), pytest.param( @@ -422,9 +426,11 @@ def static_method(): ), pytest.param( GetFrame().inherited_instance_method_wrapped()(), - "wrapped" - if sys.version_info < (3, 11) - else "GetFrameBase.inherited_instance_method_wrapped..wrapped", + ( + "wrapped" + if sys.version_info < (3, 11) + else "GetFrameBase.inherited_instance_method_wrapped..wrapped" + ), id="instance_method_wrapped", ), pytest.param( @@ -434,16 +440,20 @@ def static_method(): ), pytest.param( GetFrame().inherited_class_method_wrapped()(), - "wrapped" - if sys.version_info < (3, 11) - else "GetFrameBase.inherited_class_method_wrapped..wrapped", + ( + "wrapped" + if sys.version_info < (3, 11) + else "GetFrameBase.inherited_class_method_wrapped..wrapped" + ), id="inherited_class_method_wrapped", ), pytest.param( GetFrame().inherited_static_method(), - "inherited_static_method" - if sys.version_info < (3, 11) - else "GetFrameBase.inherited_static_method", + ( + "inherited_static_method" + if sys.version_info < (3, 11) + else "GetFrameBase.inherited_static_method" + ), id="inherited_static_method", ), ],