diff --git a/pyproject.toml b/pyproject.toml index e0cef5f340..0ff5d8da58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -299,10 +299,9 @@ select = [ "W", # pycodestyle warnings (same as flake8 default) "F", # Pyflakes (same as flake8 default) "I", - # Note: B and N rules are NOT enabled by default in flake8 - # They were only active through the plugins, which may not have been fully enabled "T20", # print() and pprint() calls "PT011", # pytest.raises() too broad + "RUF100", # Unused noqa directive ] # Use ONLY the same ignores as the original flake8 config + compatibility for this codebase @@ -311,9 +310,6 @@ ignore = [ "E501", # Line too long "E402", # Module level import not at top of file "E731", # Do not assign a lambda expression, use a def - "B014", # Redundant exception types - "N812", # Lowercase imported as non-lowercase - "N804", # First argument of classmethod should be named cls # Additional ignores for codebase compatibility "E721", # Use isinstance instead of type() == - existing pattern in this codebase diff --git a/sentry_sdk/_init_implementation.py b/sentry_sdk/_init_implementation.py index 923fcf6df8..a4de802ae4 100644 --- a/sentry_sdk/_init_implementation.py +++ b/sentry_sdk/_init_implementation.py @@ -67,7 +67,7 @@ def _init(*args: "Optional[str]", **kwargs: "Any") -> "ContextManager[Any]": # Use `ClientConstructor` to define the argument types of `init` and # `ContextManager[Any]` to tell static analyzers about the return type. - class init(sentry_sdk.consts.ClientConstructor, _InitGuard): # noqa: N801 + class init(sentry_sdk.consts.ClientConstructor, _InitGuard): pass else: diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index 16bb8ac02b..b281ccdad5 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -1559,7 +1559,7 @@ async def __aexit__(self, exc_type: "Any", exc_value: "Any", tb: "Any") -> None: # Use `ClientConstructor` to define the argument types of `init` and # `Dict[str, Any]` to tell static analyzers about the return type. - class get_options(ClientConstructor, Dict[str, Any]): # noqa: N801 + class get_options(ClientConstructor, Dict[str, Any]): pass class Client(ClientConstructor, _Client): diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 95decc19bc..acd0598bde 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -1388,10 +1388,10 @@ def __init__( environment: "Optional[str]" = None, server_name: "Optional[str]" = None, shutdown_timeout: float = 2, - integrations: "Sequence[sentry_sdk.integrations.Integration]" = [], # noqa: B006 + integrations: "Sequence[sentry_sdk.integrations.Integration]" = [], ignore_spans: "Optional[IgnoreSpansConfig]" = None, - in_app_include: "List[str]" = [], # noqa: B006 - in_app_exclude: "List[str]" = [], # noqa: B006 + in_app_include: "List[str]" = [], + in_app_exclude: "List[str]" = [], default_integrations: bool = True, dist: "Optional[str]" = None, transport: "Optional[Union[sentry_sdk.transport.Transport, Type[sentry_sdk.transport.Transport], Callable[[Event], None]]]" = None, @@ -1401,7 +1401,7 @@ def __init__( data_collection: "Optional[DataCollectionUserOptions]" = None, http_proxy: "Optional[str]" = None, https_proxy: "Optional[str]" = None, - ignore_errors: "Sequence[Union[type, str]]" = [], # noqa: B006 + ignore_errors: "Sequence[Union[type, str]]" = [], max_request_body_size: str = "medium", socket_options: "Optional[List[Tuple[int, int, int | bytes]]]" = None, keep_alive: "Optional[bool]" = None, @@ -1423,7 +1423,7 @@ def __init__( disabled_integrations: "Optional[Sequence[Union[sentry_sdk.integrations.Integration, type[sentry_sdk.integrations.Integration]]]]" = None, auto_session_tracking: bool = True, send_client_reports: bool = True, - _experiments: "Experiments" = {}, # noqa: B006 + _experiments: "Experiments" = {}, proxy_headers: "Optional[Dict[str, str]]" = None, instrumenter: "Optional[str]" = INSTRUMENTER.SENTRY, before_send_transaction: "Optional[TransactionProcessor]" = None, @@ -1431,10 +1431,8 @@ def __init__( enable_tracing: "Optional[bool]" = None, include_local_variables: "Optional[bool]" = True, include_source_context: "Optional[bool]" = True, - trace_propagation_targets: "Optional[Sequence[str]]" = [ # noqa: B006 - MATCH_ALL - ], - functions_to_trace: "Sequence[Dict[str, str]]" = [], # noqa: B006 + trace_propagation_targets: "Optional[Sequence[str]]" = [MATCH_ALL], + functions_to_trace: "Sequence[Dict[str, str]]" = [], event_scrubber: "Optional[sentry_sdk.scrubber.EventScrubber]" = None, max_value_length: "Optional[int]" = DEFAULT_MAX_VALUE_LENGTH, enable_backpressure_handling: bool = True, diff --git a/sentry_sdk/crons/decorator.py b/sentry_sdk/crons/decorator.py index fd4677709d..3238a88bd4 100644 --- a/sentry_sdk/crons/decorator.py +++ b/sentry_sdk/crons/decorator.py @@ -26,7 +26,7 @@ R = TypeVar("R") -class monitor: # noqa: N801 +class monitor: """ Decorator/context manager to capture checkin events for a monitor. diff --git a/sentry_sdk/integrations/__init__.py b/sentry_sdk/integrations/__init__.py index e61365cc7f..ad250acf42 100644 --- a/sentry_sdk/integrations/__init__.py +++ b/sentry_sdk/integrations/__init__.py @@ -315,7 +315,7 @@ def _check_minimum_version( return -class DidNotEnable(Exception): # noqa: N818 +class DidNotEnable(Exception): """ The integration could not be enabled due to a trivial user error like `flask` not being installed for the `FlaskIntegration`. diff --git a/sentry_sdk/integrations/asgi.py b/sentry_sdk/integrations/asgi.py index 9c35351ebb..b1ef63ff84 100644 --- a/sentry_sdk/integrations/asgi.py +++ b/sentry_sdk/integrations/asgi.py @@ -97,7 +97,7 @@ def _looks_like_asgi3(app: "Any") -> bool: elif inspect.isfunction(app): return iscoroutinefunction(app) else: - call = getattr(app, "__call__", None) # noqa + call = getattr(app, "__call__", None) return iscoroutinefunction(call) diff --git a/sentry_sdk/integrations/cloud_resource_context.py b/sentry_sdk/integrations/cloud_resource_context.py index f6285d0a9b..6eb22af0e7 100644 --- a/sentry_sdk/integrations/cloud_resource_context.py +++ b/sentry_sdk/integrations/cloud_resource_context.py @@ -27,7 +27,7 @@ ) -class CLOUD_PROVIDER: # noqa: N801 +class CLOUD_PROVIDER: """ Name of the cloud provider. see https://opentelemetry.io/docs/reference/specification/resource/semantic_conventions/cloud/ @@ -41,7 +41,7 @@ class CLOUD_PROVIDER: # noqa: N801 TENCENT = "tencent_cloud" -class CLOUD_PLATFORM: # noqa: N801 +class CLOUD_PLATFORM: """ The cloud platform. see https://opentelemetry.io/docs/reference/specification/resource/semantic_conventions/cloud/ diff --git a/sentry_sdk/integrations/litestar.py b/sentry_sdk/integrations/litestar.py index 593ac158aa..612c4fbfe8 100644 --- a/sentry_sdk/integrations/litestar.py +++ b/sentry_sdk/integrations/litestar.py @@ -144,7 +144,7 @@ def resolve_middleware_wrapper(self: "BaseRouteHandler") -> "list[Middleware]": def enable_span_for_middleware(middleware: "Middleware") -> "Middleware": if ( - not hasattr(middleware, "__call__") # noqa: B004 + not hasattr(middleware, "__call__") or middleware is SentryLitestarASGIMiddleware ): return middleware diff --git a/sentry_sdk/integrations/redis/redis.py b/sentry_sdk/integrations/redis/redis.py index e704c9bc6a..2bcc3fe367 100644 --- a/sentry_sdk/integrations/redis/redis.py +++ b/sentry_sdk/integrations/redis/redis.py @@ -20,7 +20,7 @@ def _get_redis_command_args(command: "Any") -> "Sequence[Any]": return command[0] -def _patch_redis(StrictRedis: "Any", client: "Any") -> None: # noqa: N803 +def _patch_redis(StrictRedis: "Any", client: "Any") -> None: patch_redis_client( StrictRedis, is_cluster=False, diff --git a/sentry_sdk/integrations/rust_tracing.py b/sentry_sdk/integrations/rust_tracing.py index d02b7fb5ab..c8d5a10d60 100644 --- a/sentry_sdk/integrations/rust_tracing.py +++ b/sentry_sdk/integrations/rust_tracing.py @@ -200,7 +200,7 @@ def on_new_span( if message is not None: sentry_span_name = message elif module_path is not None and name is not None: - sentry_span_name = f"{module_path}::{name}" # noqa: E231 + sentry_span_name = f"{module_path}::{name}" elif name is not None: sentry_span_name = name else: diff --git a/sentry_sdk/integrations/spark/spark_driver.py b/sentry_sdk/integrations/spark/spark_driver.py index a83532b6a6..e614b6762f 100644 --- a/sentry_sdk/integrations/spark/spark_driver.py +++ b/sentry_sdk/integrations/spark/spark_driver.py @@ -117,79 +117,79 @@ def _setup_sentry_tracing() -> None: class SparkListener: - def onApplicationEnd(self, applicationEnd: "Any") -> None: # noqa: N802,N803 + def onApplicationEnd(self, applicationEnd: "Any") -> None: pass - def onApplicationStart(self, applicationStart: "Any") -> None: # noqa: N802,N803 + def onApplicationStart(self, applicationStart: "Any") -> None: pass - def onBlockManagerAdded(self, blockManagerAdded: "Any") -> None: # noqa: N802,N803 + def onBlockManagerAdded(self, blockManagerAdded: "Any") -> None: pass - def onBlockManagerRemoved(self, blockManagerRemoved: "Any") -> None: # noqa: N802,N803 + def onBlockManagerRemoved(self, blockManagerRemoved: "Any") -> None: pass - def onBlockUpdated(self, blockUpdated: "Any") -> None: # noqa: N802,N803 + def onBlockUpdated(self, blockUpdated: "Any") -> None: pass - def onEnvironmentUpdate(self, environmentUpdate: "Any") -> None: # noqa: N802,N803 + def onEnvironmentUpdate(self, environmentUpdate: "Any") -> None: pass - def onExecutorAdded(self, executorAdded: "Any") -> None: # noqa: N802,N803 + def onExecutorAdded(self, executorAdded: "Any") -> None: pass - def onExecutorBlacklisted(self, executorBlacklisted: "Any") -> None: # noqa: N802,N803 + def onExecutorBlacklisted(self, executorBlacklisted: "Any") -> None: pass - def onExecutorBlacklistedForStage( # noqa: N802 + def onExecutorBlacklistedForStage( self, - executorBlacklistedForStage: "Any", # noqa: N803 + executorBlacklistedForStage: "Any", ) -> None: pass - def onExecutorMetricsUpdate(self, executorMetricsUpdate: "Any") -> None: # noqa: N802,N803 + def onExecutorMetricsUpdate(self, executorMetricsUpdate: "Any") -> None: pass - def onExecutorRemoved(self, executorRemoved: "Any") -> None: # noqa: N802,N803 + def onExecutorRemoved(self, executorRemoved: "Any") -> None: pass - def onJobEnd(self, jobEnd: "Any") -> None: # noqa: N802,N803 + def onJobEnd(self, jobEnd: "Any") -> None: pass - def onJobStart(self, jobStart: "Any") -> None: # noqa: N802,N803 + def onJobStart(self, jobStart: "Any") -> None: pass - def onNodeBlacklisted(self, nodeBlacklisted: "Any") -> None: # noqa: N802,N803 + def onNodeBlacklisted(self, nodeBlacklisted: "Any") -> None: pass - def onNodeBlacklistedForStage(self, nodeBlacklistedForStage: "Any") -> None: # noqa: N802,N803 + def onNodeBlacklistedForStage(self, nodeBlacklistedForStage: "Any") -> None: pass - def onNodeUnblacklisted(self, nodeUnblacklisted: "Any") -> None: # noqa: N802,N803 + def onNodeUnblacklisted(self, nodeUnblacklisted: "Any") -> None: pass - def onOtherEvent(self, event: "Any") -> None: # noqa: N802,N803 + def onOtherEvent(self, event: "Any") -> None: pass - def onSpeculativeTaskSubmitted(self, speculativeTask: "Any") -> None: # noqa: N802,N803 + def onSpeculativeTaskSubmitted(self, speculativeTask: "Any") -> None: pass - def onStageCompleted(self, stageCompleted: "Any") -> None: # noqa: N802,N803 + def onStageCompleted(self, stageCompleted: "Any") -> None: pass - def onStageSubmitted(self, stageSubmitted: "Any") -> None: # noqa: N802,N803 + def onStageSubmitted(self, stageSubmitted: "Any") -> None: pass - def onTaskEnd(self, taskEnd: "Any") -> None: # noqa: N802,N803 + def onTaskEnd(self, taskEnd: "Any") -> None: pass - def onTaskGettingResult(self, taskGettingResult: "Any") -> None: # noqa: N802,N803 + def onTaskGettingResult(self, taskGettingResult: "Any") -> None: pass - def onTaskStart(self, taskStart: "Any") -> None: # noqa: N802,N803 + def onTaskStart(self, taskStart: "Any") -> None: pass - def onUnpersistRDD(self, unpersistRDD: "Any") -> None: # noqa: N802,N803 + def onUnpersistRDD(self, unpersistRDD: "Any") -> None: pass class Java: @@ -207,14 +207,14 @@ def _add_breadcrumb( level=level, message=message, data=data ) - def onJobStart(self, jobStart: "Any") -> None: # noqa: N802,N803 + def onJobStart(self, jobStart: "Any") -> None: sentry_sdk.get_isolation_scope().clear_breadcrumbs() message = "Job {} Started".format(jobStart.jobId()) self._add_breadcrumb(level="info", message=message) _set_app_properties() - def onJobEnd(self, jobEnd: "Any") -> None: # noqa: N802,N803 + def onJobEnd(self, jobEnd: "Any") -> None: level = "" message = "" data = {"result": jobEnd.jobResult().toString()} @@ -228,7 +228,7 @@ def onJobEnd(self, jobEnd: "Any") -> None: # noqa: N802,N803 self._add_breadcrumb(level=level, message=message, data=data) - def onStageSubmitted(self, stageSubmitted: "Any") -> None: # noqa: N802,N803 + def onStageSubmitted(self, stageSubmitted: "Any") -> None: stage_info = stageSubmitted.stageInfo() message = "Stage {} Submitted".format(stage_info.stageId()) @@ -240,7 +240,7 @@ def onStageSubmitted(self, stageSubmitted: "Any") -> None: # noqa: N802,N803 self._add_breadcrumb(level="info", message=message, data=data) _set_app_properties() - def onStageCompleted(self, stageCompleted: "Any") -> None: # noqa: N802,N803 + def onStageCompleted(self, stageCompleted: "Any") -> None: from py4j.protocol import Py4JJavaError # type: ignore stage_info = stageCompleted.stageInfo() diff --git a/sentry_sdk/integrations/starlite.py b/sentry_sdk/integrations/starlite.py index 398412c762..70a1540263 100644 --- a/sentry_sdk/integrations/starlite.py +++ b/sentry_sdk/integrations/starlite.py @@ -129,7 +129,7 @@ def resolve_middleware_wrapper(self: "BaseRouteHandler") -> "list[Middleware]": def enable_span_for_middleware(middleware: "Middleware") -> "Middleware": if ( - not hasattr(middleware, "__call__") # noqa: B004 + not hasattr(middleware, "__call__") or middleware is SentryStarliteASGIMiddleware ): return middleware diff --git a/sentry_sdk/integrations/threading.py b/sentry_sdk/integrations/threading.py index f3ba046332..5f1e2e1bf1 100644 --- a/sentry_sdk/integrations/threading.py +++ b/sentry_sdk/integrations/threading.py @@ -49,7 +49,7 @@ def setup_once() -> None: old_start = Thread.start try: - from django import VERSION as django_version # noqa: N811 + from django import VERSION as django_version except ImportError: django_version = None diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index 4d4c35ce39..dd91da3b4d 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -723,7 +723,7 @@ def _fill_sample_rand(self) -> None: ) return - self.baggage.sentry_items["sample_rand"] = f"{sample_rand:.6f}" # noqa: E231 + self.baggage.sentry_items["sample_rand"] = f"{sample_rand:.6f}" def _sample_rand(self) -> "Optional[str]": """Convenience method to get the sample_rand value from the baggage.""" @@ -859,7 +859,7 @@ def populate_from_transaction( options = client.options or {} sentry_items["trace_id"] = transaction.trace_id - sentry_items["sample_rand"] = f"{transaction._sample_rand:.6f}" # noqa: E231 + sentry_items["sample_rand"] = f"{transaction._sample_rand:.6f}" if options.get("environment"): sentry_items["environment"] = options["environment"] diff --git a/sentry_sdk/transport.py b/sentry_sdk/transport.py index 85308c7797..f459c87c01 100644 --- a/sentry_sdk/transport.py +++ b/sentry_sdk/transport.py @@ -73,10 +73,10 @@ KEEP_ALIVE_SOCKET_OPTIONS = [] for option in [ - (socket.SOL_SOCKET, lambda: getattr(socket, "SO_KEEPALIVE"), 1), # noqa: B009 - (socket.SOL_TCP, lambda: getattr(socket, "TCP_KEEPIDLE"), 45), # noqa: B009 - (socket.SOL_TCP, lambda: getattr(socket, "TCP_KEEPINTVL"), 10), # noqa: B009 - (socket.SOL_TCP, lambda: getattr(socket, "TCP_KEEPCNT"), 6), # noqa: B009 + (socket.SOL_SOCKET, lambda: getattr(socket, "SO_KEEPALIVE"), 1), + (socket.SOL_TCP, lambda: getattr(socket, "TCP_KEEPIDLE"), 45), + (socket.SOL_TCP, lambda: getattr(socket, "TCP_KEEPINTVL"), 10), + (socket.SOL_TCP, lambda: getattr(socket, "TCP_KEEPCNT"), 6), ]: try: KEEP_ALIVE_SOCKET_OPTIONS.append((option[0], option[1](), option[2])) diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 6d4d46993f..a6faf613ee 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -1314,7 +1314,7 @@ def parse_version(version: str) -> "Optional[Tuple[int, ...]]": This uses the parsing logic from PEP 440: https://peps.python.org/pep-0440/#appendix-b-parsing-version-strings-with-regular-expressions """ - VERSION_PATTERN = r""" # noqa: N806 + VERSION_PATTERN = r""" v? (?: (?:(?P[0-9]+)!)? # epoch @@ -1546,7 +1546,7 @@ def transaction_from_function(func: "Callable[..., Any]") -> "Optional[str]": disable_capture_event = ContextVar("disable_capture_event") -class ServerlessTimeoutWarning(Exception): # noqa: N818 +class ServerlessTimeoutWarning(Exception): """Raised when a serverless method is about to reach its timeout.""" pass diff --git a/tests/conftest.py b/tests/conftest.py index 0b7f2e9def..b75c2868f3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -57,7 +57,7 @@ import sentry_sdk import sentry_sdk.utils from sentry_sdk.envelope import Envelope, parse_json -from sentry_sdk.integrations import ( # noqa: F401 +from sentry_sdk.integrations import ( _DEFAULT_INTEGRATIONS, _installed_integrations, _processed_integrations, @@ -1675,7 +1675,7 @@ def inner( class MockServerRequestHandler(BaseHTTPRequestHandler): - def do_GET(self): # noqa: N802 + def do_GET(self): # Process an HTTP GET request and return a response. # If the path ends with /status/, return status code . # Otherwise return a 200 response. diff --git a/tests/integrations/aiohttp/test_aiohttp.py b/tests/integrations/aiohttp/test_aiohttp.py index 701ea7d889..ee1d7ec301 100644 --- a/tests/integrations/aiohttp/test_aiohttp.py +++ b/tests/integrations/aiohttp/test_aiohttp.py @@ -408,8 +408,8 @@ async def hello(request): async def test_traces_sampler_gets_request_object_in_sampling_context( sentry_init, aiohttp_client, - DictionaryContaining, # noqa: N803 - ObjectDescribedBy, # noqa: N803 + DictionaryContaining, + ObjectDescribedBy, ): traces_sampler = mock.Mock() sentry_init( diff --git a/tests/integrations/asgi/test_asgi.py b/tests/integrations/asgi/test_asgi.py index 97222edebc..f15a7ec36a 100644 --- a/tests/integrations/asgi/test_asgi.py +++ b/tests/integrations/asgi/test_asgi.py @@ -279,7 +279,7 @@ async def test_capture_transaction_with_error( asgi3_app_with_error, capture_events, capture_items, - DictionaryContaining, # noqa: N803 + DictionaryContaining, span_streaming, ): sentry_init( diff --git a/tests/integrations/asyncio/test_asyncio.py b/tests/integrations/asyncio/test_asyncio.py index 962df3574b..20e79394f0 100644 --- a/tests/integrations/asyncio/test_asyncio.py +++ b/tests/integrations/asyncio/test_asyncio.py @@ -328,7 +328,7 @@ def test_patch_asyncio(mock_get_running_loop): @minimum_python_38 @patch("asyncio.get_running_loop") @patch("sentry_sdk.integrations.asyncio.Task") -def test_sentry_task_factory_no_factory(MockTask, mock_get_running_loop): # noqa: N803 +def test_sentry_task_factory_no_factory(MockTask, mock_get_running_loop): mock_loop = mock_get_running_loop.return_value mock_coro = MagicMock() @@ -386,7 +386,7 @@ def test_sentry_task_factory_with_factory(mock_get_running_loop): @patch("sentry_sdk.integrations.asyncio.Task") def test_sentry_task_factory_context_no_factory( MockTask, - mock_get_running_loop, # noqa: N803 + mock_get_running_loop, ): mock_loop = mock_get_running_loop.return_value mock_coro = MagicMock() diff --git a/tests/integrations/aws_lambda/test_aws_lambda.py b/tests/integrations/aws_lambda/test_aws_lambda.py index 72c7faa190..fff8ffc320 100644 --- a/tests/integrations/aws_lambda/test_aws_lambda.py +++ b/tests/integrations/aws_lambda/test_aws_lambda.py @@ -100,7 +100,7 @@ def lambda_client(): """ return boto3.client( "lambda", - endpoint_url=f"http://127.0.0.1:{SAM_PORT}", # noqa: E231 + endpoint_url=f"http://127.0.0.1:{SAM_PORT}", aws_access_key_id="dummy", aws_secret_access_key="dummy", region_name="us-east-1", diff --git a/tests/integrations/aws_lambda/utils.py b/tests/integrations/aws_lambda/utils.py index ac14fd56ef..6fab712014 100644 --- a/tests/integrations/aws_lambda/utils.py +++ b/tests/integrations/aws_lambda/utils.py @@ -94,7 +94,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None: }, ) - dsn = f"http://123@{get_host_ip()}:9999/0" # noqa: E231 + dsn = f"http://123@{get_host_ip()}:9999/0" print("[LocalLambdaStack] Using Sentry DSN: %s" % dsn) print( @@ -216,7 +216,7 @@ def wait_for_stack(cls, timeout=60, port=SAM_PORT): try: # Try to connect to SAM - response = requests.get(f"http://127.0.0.1:{port}/") # noqa: E231 + response = requests.get(f"http://127.0.0.1:{port}/") if response.status_code == 200 or response.status_code == 404: return diff --git a/tests/integrations/celery/test_celery.py b/tests/integrations/celery/test_celery.py index cd9d716cd2..b2afd49733 100644 --- a/tests/integrations/celery/test_celery.py +++ b/tests/integrations/celery/test_celery.py @@ -652,7 +652,7 @@ def test_traces_sampler_gets_task_info_in_sampling_context( span_streaming, init_celery, celery_invocation, - DictionaryContaining, # noqa:N803 + DictionaryContaining, ): traces_sampler = mock.Mock(return_value=1.0) celery = init_celery( @@ -999,7 +999,7 @@ def test_messaging_system( ) # Does not need to be a real URL, since we use always eager - celery.conf.broker_url = f"{system}://example.com" # noqa: E231 + celery.conf.broker_url = f"{system}://example.com" @celery.task() def task(): ... @@ -1035,7 +1035,7 @@ def publish(*args, **kwargs): traces_sample_rate=1.0, trace_lifecycle="stream" if span_streaming else "static", ) - celery = Celery(__name__, broker=f"{system}://example.com") # noqa: E231 + celery = Celery(__name__, broker=f"{system}://example.com") @celery.task() def task(): ... @@ -1110,7 +1110,7 @@ def tests_span_origin_consumer( traces_sample_rate=1.0, trace_lifecycle="stream" if span_streaming else "static", ) - celery.conf.broker_url = "redis://example.com" # noqa: E231 + celery.conf.broker_url = "redis://example.com" @celery.task() def task(): ... @@ -1150,7 +1150,7 @@ def publish(*args, **kwargs): traces_sample_rate=1.0, trace_lifecycle="stream" if span_streaming else "static", ) - celery = Celery(__name__, broker="redis://example.com") # noqa: E231 + celery = Celery(__name__, broker="redis://example.com") @celery.task() def task(): ... @@ -1201,7 +1201,7 @@ def test_send_task_wrapped( traces_sample_rate=1.0, trace_lifecycle="stream" if span_streaming else "static", ) - celery = Celery(__name__, broker="redis://example.com") # noqa: E231 + celery = Celery(__name__, broker="redis://example.com") if span_streaming: items = capture_items("span") diff --git a/tests/integrations/celery/test_celery_beat_crons.py b/tests/integrations/celery/test_celery_beat_crons.py index bec10644cb..2cf3559426 100644 --- a/tests/integrations/celery/test_celery_beat_crons.py +++ b/tests/integrations/celery/test_celery_beat_crons.py @@ -451,7 +451,7 @@ def test_exclude_beat_tasks_option( with mock.patch( "sentry_sdk.integrations.celery.beat.Scheduler", fake_scheduler - ) as Scheduler: # noqa: N806 + ) as Scheduler: with mock.patch( "sentry_sdk.integrations.celery.sentry_sdk.get_client", return_value=fake_client, @@ -507,7 +507,7 @@ def test_exclude_redbeat_tasks_option( with mock.patch( "sentry_sdk.integrations.celery.beat.RedBeatScheduler", fake_redbeat_scheduler - ) as RedBeatScheduler: # noqa: N806 + ) as RedBeatScheduler: with mock.patch( "sentry_sdk.integrations.celery.sentry_sdk.get_client", return_value=fake_client, diff --git a/tests/integrations/django/myapp/settings.py b/tests/integrations/django/myapp/settings.py index d70adf63ec..a04bf36531 100644 --- a/tests/integrations/django/myapp/settings.py +++ b/tests/integrations/django/myapp/settings.py @@ -63,7 +63,7 @@ def process_response(self, request, response): return response -def TestFunctionMiddleware(get_response): # noqa: N802 +def TestFunctionMiddleware(get_response): def middleware(request): return get_response(request) diff --git a/tests/integrations/django/myapp/views.py b/tests/integrations/django/myapp/views.py index 4261f341df..b5e4825175 100644 --- a/tests/integrations/django/myapp/views.py +++ b/tests/integrations/django/myapp/views.py @@ -237,7 +237,7 @@ def template_test3(request, *args, **kwargs): @csrf_exempt def template_test4(request, *args, **kwargs): User.objects.create_user("john", "lennon@thebeatles.com", "johnpassword") - my_queryset = User.objects.all() # noqa + my_queryset = User.objects.all() template_context = { "user_age": 25, diff --git a/tests/integrations/django/test_db_query_data.py b/tests/integrations/django/test_db_query_data.py index 0739b0992b..393c6620bb 100644 --- a/tests/integrations/django/test_db_query_data.py +++ b/tests/integrations/django/test_db_query_data.py @@ -623,7 +623,7 @@ def test_no_query_source_if_duration_too_short( # trigger Django to open a new connection by marking the existing one as None. connections["postgres"].connection = None - class fake_record_sql_queries: # noqa: N801 + class fake_record_sql_queries: def __init__(self, *args, **kwargs): self._ctx_mgr = record_sql_queries(*args, **kwargs) @@ -729,7 +729,7 @@ def test_query_source_if_duration_over_threshold( # trigger Django to open a new connection by marking the existing one as None. connections["postgres"].connection = None - class fake_record_sql_queries: # noqa: N801 + class fake_record_sql_queries: def __init__(self, *args, **kwargs): self._ctx_mgr = record_sql_queries(*args, **kwargs) diff --git a/tests/integrations/gcp/test_gcp.py b/tests/integrations/gcp/test_gcp.py index 57854ad5a4..389adbf6ca 100644 --- a/tests/integrations/gcp/test_gcp.py +++ b/tests/integrations/gcp/test_gcp.py @@ -302,7 +302,7 @@ def cloud_function(functionhandler, event): def test_traces_sampler_gets_correct_values_in_sampling_context( run_cloud_function, - DictionaryContaining, # noqa:N803 + DictionaryContaining, ): # TODO: There are some decent sized hacks below. For more context, see the # long comment in the test of the same name in the AWS integration. The diff --git a/tests/integrations/graphene/test_graphene.py b/tests/integrations/graphene/test_graphene.py index 724f68b220..63296d50cb 100644 --- a/tests/integrations/graphene/test_graphene.py +++ b/tests/integrations/graphene/test_graphene.py @@ -43,10 +43,10 @@ class Query(ObjectType): hello = String(first_name=String(default_value="stranger")) goodbye = String() - def resolve_hello(root, info, first_name): # noqa: N805 + def resolve_hello(root, info, first_name): return "Hello {}!".format(first_name) - def resolve_goodbye(root, info): # noqa: N805 + def resolve_goodbye(root, info): raise RuntimeError("oh no!") diff --git a/tests/integrations/grpc/test_grpc.py b/tests/integrations/grpc/test_grpc.py index f50a2f62d1..e5a19f2f1c 100644 --- a/tests/integrations/grpc/test_grpc.py +++ b/tests/integrations/grpc/test_grpc.py @@ -44,7 +44,7 @@ def _set_up( server.start() # Create channel connected to our server - channel = grpc.insecure_channel(f"localhost:{port}") # noqa: E231 + channel = grpc.insecure_channel(f"localhost:{port}") return server, channel @@ -759,7 +759,7 @@ class TestService(gRPCTestServiceServicer): events = [] @staticmethod - def TestServe(request, context): # noqa: N802 + def TestServe(request, context): client = sentry_sdk.get_client() span_streaming = has_span_streaming_enabled(client.options) @@ -783,16 +783,16 @@ def TestServe(request, context): # noqa: N802 return gRPCTestMessage(text=request.text) @staticmethod - def TestUnaryStream(request, context): # noqa: N802 + def TestUnaryStream(request, context): for _ in range(3): yield gRPCTestMessage(text=request.text) @staticmethod - def TestStreamStream(request, context): # noqa: N802 + def TestStreamStream(request, context): for r in request: yield r @staticmethod - def TestStreamUnary(request, context): # noqa: N802 + def TestStreamUnary(request, context): requests = [r for r in request] return requests.pop() diff --git a/tests/integrations/grpc/test_grpc_aio.py b/tests/integrations/grpc/test_grpc_aio.py index 217dc110d2..ae8cd72791 100644 --- a/tests/integrations/grpc/test_grpc_aio.py +++ b/tests/integrations/grpc/test_grpc_aio.py @@ -51,7 +51,7 @@ async def inner(span_streaming: bool): await asyncio.create_task(server.start()) # Create channel connected to our server - channel = grpc.aio.insecure_channel(f"localhost:{port}") # noqa: E231 + channel = grpc.aio.insecure_channel(f"localhost:{port}") return server, channel @@ -88,9 +88,7 @@ async def test_noop_for_unimplemented_method( items = capture_items("span") try: - async with grpc.aio.insecure_channel( - f"localhost:{port}" # noqa: E231 - ) as channel: + async with grpc.aio.insecure_channel(f"localhost:{port}") as channel: stub = gRPCTestServiceStub(channel) with pytest.raises(grpc.RpcError) as exc: await stub.TestServe(gRPCTestMessage(text="test")) @@ -105,9 +103,7 @@ async def test_noop_for_unimplemented_method( events = capture_events() try: - async with grpc.aio.insecure_channel( - f"localhost:{port}" # noqa: E231 - ) as channel: + async with grpc.aio.insecure_channel(f"localhost:{port}") as channel: stub = gRPCTestServiceStub(channel) with pytest.raises(grpc.RpcError) as exc: await stub.TestServe(gRPCTestMessage(text="test")) @@ -539,7 +535,7 @@ def __init__(self): super().__init__("test") @classmethod - async def TestServe(cls, request, context): # noqa: N802 + async def TestServe(cls, request, context): client = sentry_sdk.get_client() span_streaming = has_span_streaming_enabled(client.options) @@ -569,16 +565,16 @@ async def TestServe(cls, request, context): # noqa: N802 return gRPCTestMessage(text=request.text) @classmethod - async def TestUnaryStream(cls, request, context): # noqa: N802 + async def TestUnaryStream(cls, request, context): for _ in range(3): yield gRPCTestMessage(text=request.text) @classmethod - async def TestStreamStream(cls, request, context): # noqa: N802 + async def TestStreamStream(cls, request, context): async for r in request: yield r @classmethod - async def TestStreamUnary(cls, request, context): # noqa: N802 + async def TestStreamUnary(cls, request, context): requests = [r async for r in request] return requests.pop() diff --git a/tests/integrations/langgraph/test_langgraph.py b/tests/integrations/langgraph/test_langgraph.py index 7b6a6cc3d9..9b92149aca 100644 --- a/tests/integrations/langgraph/test_langgraph.py +++ b/tests/integrations/langgraph/test_langgraph.py @@ -34,7 +34,7 @@ def mock_langgraph_imports(): mock_state_graph, mock_pregel = mock_langgraph_imports() -from sentry_sdk.integrations.langgraph import ( # noqa: E402 +from sentry_sdk.integrations.langgraph import ( LanggraphIntegration, _parse_langgraph_messages, _wrap_pregel_ainvoke, diff --git a/tests/integrations/openai/test_openai.py b/tests/integrations/openai/test_openai.py index e578b03fdc..cf78d2dff0 100644 --- a/tests/integrations/openai/test_openai.py +++ b/tests/integrations/openai/test_openai.py @@ -1796,7 +1796,7 @@ def test_streaming_chat_completion_no_prompts( assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span["attributes"] try: - import tiktoken # type: ignore # noqa # pylint: disable=unused-import + import tiktoken # type: ignore # pylint: disable=unused-import assert span["attributes"]["gen_ai.usage.output_tokens"] == 2 assert span["attributes"]["gen_ai.usage.input_tokens"] == 7 @@ -2497,7 +2497,7 @@ def test_streaming_chat_completion( assert "hello world" in span["attributes"][SPANDATA.GEN_AI_RESPONSE_TEXT] try: - import tiktoken # type: ignore # noqa # pylint: disable=unused-import + import tiktoken # type: ignore # pylint: disable=unused-import assert ( span["attributes"]["gen_ai.usage.output_tokens"] @@ -2708,7 +2708,7 @@ async def test_streaming_chat_completion_async_no_prompts( assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span["attributes"] try: - import tiktoken # type: ignore # noqa # pylint: disable=unused-import + import tiktoken # type: ignore # pylint: disable=unused-import assert span["attributes"]["gen_ai.usage.output_tokens"] == 2 assert span["attributes"]["gen_ai.usage.input_tokens"] == 7 @@ -2993,7 +2993,7 @@ async def test_streaming_chat_completion_async( assert "hello world" in span["attributes"][SPANDATA.GEN_AI_RESPONSE_TEXT] try: - import tiktoken # type: ignore # noqa # pylint: disable=unused-import + import tiktoken # type: ignore # pylint: disable=unused-import assert ( span["attributes"]["gen_ai.usage.output_tokens"] diff --git a/tests/integrations/requests/test_requests.py b/tests/integrations/requests/test_requests.py index 7df431901b..a974bd574d 100644 --- a/tests/integrations/requests/test_requests.py +++ b/tests/integrations/requests/test_requests.py @@ -16,7 +16,7 @@ def test_crumb_capture(sentry_init, capture_events): sentry_init(integrations=[StdlibIntegration()], send_default_pii=True) events = capture_events() - url = f"http://localhost:{PORT}/hello-world" # noqa:E231 + url = f"http://localhost:{PORT}/hello-world" response = requests.get(url) capture_message("Testing!") @@ -45,7 +45,7 @@ def test_crumb_capture_span_streaming(sentry_init, capture_events, send_default_ ) events = capture_events() - url = f"http://localhost:{PORT}/hello-world" # noqa:E231 + url = f"http://localhost:{PORT}/hello-world" response = requests.get(url) capture_message("Testing!") @@ -90,7 +90,7 @@ def test_crumb_capture_client_error(sentry_init, capture_events, status_code, le events = capture_events() - url = f"http://localhost:{PORT}/status/{status_code}" # noqa:E231 + url = f"http://localhost:{PORT}/status/{status_code}" response = requests.get(url) assert response.status_code == status_code @@ -145,7 +145,7 @@ def test_crumb_capture_client_error_span_streaming( events = capture_events() - url = f"http://localhost:{PORT}/status/{status_code}" # noqa:E231 + url = f"http://localhost:{PORT}/status/{status_code}" response = requests.get(url) assert response.status_code == status_code @@ -185,7 +185,7 @@ def test_omit_url_data_if_parsing_fails(sentry_init, capture_events): events = capture_events() - url = f"http://localhost:{PORT}/ok" # noqa:E231 + url = f"http://localhost:{PORT}/ok" with mock.patch( "sentry_sdk.integrations.stdlib.parse_url", @@ -219,7 +219,7 @@ def test_omit_url_data_if_parsing_fails_span_streaming(sentry_init, capture_even events = capture_events() - url = f"http://localhost:{PORT}/ok" # noqa:E231 + url = f"http://localhost:{PORT}/ok" with mock.patch( "sentry_sdk.integrations.stdlib.parse_url", diff --git a/tests/integrations/rq/test_rq.py b/tests/integrations/rq/test_rq.py index a56666efb1..8174162c8a 100644 --- a/tests/integrations/rq/test_rq.py +++ b/tests/integrations/rq/test_rq.py @@ -500,7 +500,7 @@ def test_traces_sampler_gets_correct_values_in_sampling_context( sentry_init, DictionaryContaining, ObjectDescribedBy, - span_streaming, # noqa:N803 + span_streaming, ): traces_sampler = mock.Mock(return_value=True) sentry_init( diff --git a/tests/integrations/socket/test_socket.py b/tests/integrations/socket/test_socket.py index 7578d954e6..8d77986a08 100644 --- a/tests/integrations/socket/test_socket.py +++ b/tests/integrations/socket/test_socket.py @@ -29,7 +29,7 @@ def test_getaddrinfo_trace(sentry_init, capture_events, capture_items, span_stre assert dns_span["attributes"]["sentry.op"] == "socket.dns" assert dns_span["attributes"]["sentry.origin"] == "auto.socket.socket" - assert dns_span["name"] == f"localhost:{PORT}" # noqa: E231 + assert dns_span["name"] == f"localhost:{PORT}" assert dns_span["attributes"]["server.address"] == "localhost" assert dns_span["attributes"]["server.port"] == PORT else: @@ -42,7 +42,7 @@ def test_getaddrinfo_trace(sentry_init, capture_events, capture_items, span_stre (span,) = event["spans"] assert span["op"] == "socket.dns" - assert span["description"] == f"localhost:{PORT}" # noqa: E231 + assert span["description"] == f"localhost:{PORT}" assert span["data"] == ApproxDict( { "host": "localhost", @@ -75,12 +75,12 @@ def test_create_connection_trace( dns_span, connect_span, _root = spans assert connect_span["attributes"]["sentry.op"] == "socket.connection" - assert connect_span["name"] == f"localhost:{PORT}" # noqa: E231 + assert connect_span["name"] == f"localhost:{PORT}" assert connect_span["attributes"]["server.address"] == "localhost" assert connect_span["attributes"]["server.port"] == PORT assert dns_span["attributes"]["sentry.op"] == "socket.dns" - assert dns_span["name"] == f"localhost:{PORT}" # noqa: E231 + assert dns_span["name"] == f"localhost:{PORT}" assert dns_span["attributes"]["server.address"] == "localhost" assert dns_span["attributes"]["server.port"] == PORT else: @@ -94,7 +94,7 @@ def test_create_connection_trace( # as getaddrinfo gets called in create_connection it should also contain a dns span assert connect_span["op"] == "socket.connection" - assert connect_span["description"] == f"localhost:{PORT}" # noqa: E231 + assert connect_span["description"] == f"localhost:{PORT}" assert connect_span["data"] == ApproxDict( { "address": ["localhost", PORT], @@ -104,7 +104,7 @@ def test_create_connection_trace( ) assert dns_span["op"] == "socket.dns" - assert dns_span["description"] == f"localhost:{PORT}" # noqa: E231 + assert dns_span["description"] == f"localhost:{PORT}" assert dns_span["data"] == ApproxDict( { "host": "localhost", diff --git a/tests/integrations/spark/test_spark.py b/tests/integrations/spark/test_spark.py index e5c536713d..8aadd0435d 100644 --- a/tests/integrations/spark/test_spark.py +++ b/tests/integrations/spark/test_spark.py @@ -98,7 +98,7 @@ def test_sentry_listener_on_job_start(sentry_listener): with patch.object(listener, "_add_breadcrumb") as mock_add_breadcrumb: class MockJobStart: - def jobId(self): # noqa: N802 + def jobId(self): return "sample-job-id-start" mock_job_start = MockJobStart() @@ -119,14 +119,14 @@ def test_sentry_listener_on_job_end(sentry_listener, job_result, level): with patch.object(listener, "_add_breadcrumb") as mock_add_breadcrumb: class MockJobResult: - def toString(self): # noqa: N802 + def toString(self): return job_result class MockJobEnd: - def jobId(self): # noqa: N802 + def jobId(self): return "sample-job-id-end" - def jobResult(self): # noqa: N802 + def jobResult(self): result = MockJobResult() return result @@ -146,17 +146,17 @@ def test_sentry_listener_on_stage_submitted(sentry_listener): with patch.object(listener, "_add_breadcrumb") as mock_add_breadcrumb: class StageInfo: - def stageId(self): # noqa: N802 + def stageId(self): return "sample-stage-id-submit" def name(self): return "run-job" - def attemptId(self): # noqa: N802 + def attemptId(self): return 14 class MockStageSubmitted: - def stageInfo(self): # noqa: N802 + def stageInfo(self): stageinf = StageInfo() return stageinf @@ -177,17 +177,17 @@ def test_sentry_listener_on_stage_submitted_no_attempt_id(sentry_listener): with patch.object(listener, "_add_breadcrumb") as mock_add_breadcrumb: class StageInfo: - def stageId(self): # noqa: N802 + def stageId(self): return "sample-stage-id-submit" def name(self): return "run-job" - def attemptNumber(self): # noqa: N802 + def attemptNumber(self): return 14 class MockStageSubmitted: - def stageInfo(self): # noqa: N802 + def stageInfo(self): stageinf = StageInfo() return stageinf @@ -208,14 +208,14 @@ def test_sentry_listener_on_stage_submitted_no_attempt_id_or_number(sentry_liste with patch.object(listener, "_add_breadcrumb") as mock_add_breadcrumb: class StageInfo: - def stageId(self): # noqa: N802 + def stageId(self): return "sample-stage-id-submit" def name(self): return "run-job" class MockStageSubmitted: - def stageInfo(self): # noqa: N802 + def stageInfo(self): stageinf = StageInfo() return stageinf @@ -246,20 +246,20 @@ def get(self): raise Py4JJavaError("msg", JavaException()) class StageInfo: - def stageId(self): # noqa: N802 + def stageId(self): return "sample-stage-id-submit" def name(self): return "run-job" - def attemptId(self): # noqa: N802 + def attemptId(self): return 14 - def failureReason(self): # noqa: N802 + def failureReason(self): return FailureReason() class MockStageCompleted: - def stageInfo(self): # noqa: N802 + def stageInfo(self): return StageInfo() return MockStageCompleted() diff --git a/tests/integrations/sqlalchemy/test_sqlalchemy.py b/tests/integrations/sqlalchemy/test_sqlalchemy.py index e08bb0a423..68adb8eed0 100644 --- a/tests/integrations/sqlalchemy/test_sqlalchemy.py +++ b/tests/integrations/sqlalchemy/test_sqlalchemy.py @@ -32,7 +32,7 @@ def test_orm_queries( }, ) - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -53,7 +53,7 @@ class Address(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() bob = Person(name="Bob") @@ -108,7 +108,7 @@ def test_transactions( traces_sample_rate=1.0, ) - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -129,7 +129,7 @@ class Address(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() if span_streaming: @@ -238,7 +238,7 @@ def test_transactions_no_engine_url( traces_sample_rate=1.0, ) - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -260,7 +260,7 @@ class Address(Base): engine.url = None Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() if span_streaming: @@ -458,7 +458,7 @@ def test_query_source_disabled( items = capture_items("span") with sentry_sdk.traces.start_span(name="custom parent"): - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -470,7 +470,7 @@ class Person(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() bob = Person(name="Bob") @@ -498,7 +498,7 @@ class Person(Base): events = capture_events() with start_transaction(name="test_transaction", sampled=True): - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -510,7 +510,7 @@ class Person(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() bob = Person(name="Bob") @@ -560,7 +560,7 @@ def test_query_source_enabled( items = capture_items("span") with sentry_sdk.traces.start_span(name="custom parent"): - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -572,7 +572,7 @@ class Person(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() bob = Person(name="Bob") @@ -599,7 +599,7 @@ class Person(Base): events = capture_events() with start_transaction(name="test_transaction", sampled=True): - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -611,7 +611,7 @@ class Person(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() bob = Person(name="Bob") @@ -654,7 +654,7 @@ def test_query_source( items = capture_items("span") with sentry_sdk.traces.start_span(name="custom parent"): - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -666,7 +666,7 @@ class Person(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() bob = Person(name="Bob") @@ -708,7 +708,7 @@ class Person(Base): events = capture_events() with start_transaction(name="test_transaction", sampled=True): - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -720,7 +720,7 @@ class Person(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() bob = Person(name="Bob") @@ -786,7 +786,7 @@ def test_query_source_with_module_in_search_path( if span_streaming: items = capture_items("span") with sentry_sdk.traces.start_span(name="custom parent"): - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -798,7 +798,7 @@ class Person(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() bob = Person(name="Bob") @@ -844,7 +844,7 @@ class Person(Base): else: events = capture_events() with start_transaction(name="test_transaction", sampled=True): - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -856,7 +856,7 @@ class Person(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() bob = Person(name="Bob") @@ -914,7 +914,7 @@ def test_no_query_source_if_duration_too_short( items = capture_items("span") with sentry_sdk.traces.start_span(name="custom parent"): - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -926,13 +926,13 @@ class Person(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() bob = Person(name="Bob") session.add(bob) - class fake_record_sql_queries: # noqa: N801 + class fake_record_sql_queries: def __init__(self, *args, **kwargs): self._ctx_mgr = record_sql_queries(*args, **kwargs) @@ -972,7 +972,7 @@ def __exit__(self, type, value, traceback): events = capture_events() with start_transaction(name="test_transaction", sampled=True): - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -984,13 +984,13 @@ class Person(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() bob = Person(name="Bob") session.add(bob) - class fake_record_sql_queries: # noqa: N801 + class fake_record_sql_queries: def __init__(self, *args, **kwargs): self._ctx_mgr = record_sql_queries(*args, **kwargs) @@ -1045,7 +1045,7 @@ def test_query_source_if_duration_over_threshold( items = capture_items("span") with sentry_sdk.traces.start_span(name="custom parent"): - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -1057,13 +1057,13 @@ class Person(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() bob = Person(name="Bob") session.add(bob) - class fake_record_sql_queries: # noqa: N801 + class fake_record_sql_queries: def __init__(self, *args, **kwargs): self._ctx_mgr = record_sql_queries(*args, **kwargs) @@ -1120,7 +1120,7 @@ def __exit__(self, type, value, traceback): events = capture_events() with start_transaction(name="test_transaction", sampled=True): - Base = declarative_base() # noqa: N806 + Base = declarative_base() class Person(Base): __tablename__ = "person" @@ -1132,13 +1132,13 @@ class Person(Base): ) Base.metadata.create_all(engine) - Session = sessionmaker(bind=engine) # noqa: N806 + Session = sessionmaker(bind=engine) session = Session() bob = Person(name="Bob") session.add(bob) - class fake_record_sql_queries: # noqa: N801 + class fake_record_sql_queries: def __init__(self, *args, **kwargs): self._ctx_mgr = record_sql_queries(*args, **kwargs) diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index dc9bd2add7..dfb307b92e 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -153,7 +153,7 @@ def test_crumb_capture_client_error(sentry_init, capture_events, status_code, le sentry_init(integrations=[StdlibIntegration()], send_default_pii=True) events = capture_events() - url = f"http://localhost:{PORT}/status/{status_code}" # noqa:E231 + url = f"http://localhost:{PORT}/status/{status_code}" try: urlopen(url) except HTTPError: @@ -204,7 +204,7 @@ def test_crumb_capture_client_error_span_streaming( ) events = capture_events() - url = f"http://localhost:{PORT}/status/{status_code}" # noqa:E231 + url = f"http://localhost:{PORT}/status/{status_code}" try: urlopen(url) except HTTPError: @@ -1340,7 +1340,7 @@ def test_http_timeout( assert len(spans) == 2 span = spans[0] assert span["attributes"]["sentry.op"] == "http.client" - assert span["name"] == f"GET http://localhost:{PORT}/bla" # noqa: E231 + assert span["name"] == f"GET http://localhost:{PORT}/bla" else: envelopes = capture_envelopes() @@ -1356,7 +1356,7 @@ def test_http_timeout( span = transaction["spans"][0] assert span["op"] == "http.client" - assert span["description"] == f"GET http://localhost:{PORT}/bla" # noqa: E231 + assert span["description"] == f"GET http://localhost:{PORT}/bla" @pytest.mark.parametrize("tunnel_port", [8080, None]) @@ -1691,6 +1691,4 @@ def test_crumb_url_query_data_collection_span_streaming( assert crumb["data"][SPANDATA.URL_FULL] == f"{base_url}#frag" else: assert crumb["data"][SPANDATA.URL_QUERY] == expected_query - assert ( - crumb["data"][SPANDATA.URL_FULL] == f"{base_url}?{expected_query}#frag" # noqa: E231 - ) + assert crumb["data"][SPANDATA.URL_FULL] == f"{base_url}?{expected_query}#frag" diff --git a/tests/integrations/wsgi/test_wsgi.py b/tests/integrations/wsgi/test_wsgi.py index 4eee854ae8..b57517383c 100644 --- a/tests/integrations/wsgi/test_wsgi.py +++ b/tests/integrations/wsgi/test_wsgi.py @@ -78,7 +78,7 @@ def test_script_name_is_respected( with pytest.raises(ZeroDivisionError): # setting url with PATH_INFO: bark/, HTTP_HOST: dogs.are.great and SCRIPT_NAME: woof/woof/ - client.get(path_info, f"https://dogs.are.great/{script_name}") # noqa: E231 + client.get(path_info, f"https://dogs.are.great/{script_name}") (event,) = events @@ -146,7 +146,7 @@ def test_transaction_with_error( crashing_app, capture_events, capture_items, - DictionaryContaining, # noqa:N803 + DictionaryContaining, span_streaming, ): def dogpark(environ, start_response): @@ -213,7 +213,7 @@ def test_transaction_no_error( sentry_init, capture_events, capture_items, - DictionaryContaining, # noqa:N803 + DictionaryContaining, span_streaming, send_pii, ): @@ -464,7 +464,7 @@ def dogpark(environ, start_response): @pytest.mark.parametrize("span_streaming", [True, False]) def test_traces_sampler_gets_correct_values_in_sampling_context( sentry_init, - DictionaryContaining, # noqa:N803 + DictionaryContaining, span_streaming, ): def app(environ, start_response): diff --git a/tests/profiler/test_transaction_profiler.py b/tests/profiler/test_transaction_profiler.py index 6929dc86fb..f02e9cc89e 100644 --- a/tests/profiler/test_transaction_profiler.py +++ b/tests/profiler/test_transaction_profiler.py @@ -822,7 +822,7 @@ def ensure_running(self) -> None: ) @mock.patch("sentry_sdk.profiler.transaction_profiler.MAX_PROFILE_DURATION_NS", 5) def test_profile_processing( - DictionaryContaining, # noqa: N803 + DictionaryContaining, samples, expected, ): diff --git a/tests/test_conftest.py b/tests/test_conftest.py index a36fe17894..362ad2f8c4 100644 --- a/tests/test_conftest.py +++ b/tests/test_conftest.py @@ -24,7 +24,7 @@ def test_string_containing( test_string, expected_result, - StringContaining, # noqa: N803 + StringContaining, ): assert (test_string == StringContaining("dogs")) is expected_result @@ -50,14 +50,14 @@ def test_string_containing( def test_dictionary_containing( test_dict, expected_result, - DictionaryContaining, # noqa: N803 + DictionaryContaining, ): assert ( test_dict == DictionaryContaining({"dogs": "yes", "cats": "maybe"}) ) is expected_result -class Animal: # noqa: B903 +class Animal: def __init__(self, name=None, age=None, description=None): self.name = name self.age = age @@ -98,7 +98,7 @@ def test_object_described_by( type_and_attrs_result, type_only_result, attrs_only_result, - ObjectDescribedBy, # noqa: N803 + ObjectDescribedBy, ): assert ( test_obj == ObjectDescribedBy(type=Dog, attrs={"name": "Maisey", "age": 7}) diff --git a/tests/test_import.py b/tests/test_import.py index e5b07817cb..6c673e9552 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -1,5 +1,5 @@ # As long as this file can be imported, we are good. -from sentry_sdk import * # noqa: F403, F401 +from sentry_sdk import * # noqa: F403 def test_import(): diff --git a/tests/test_propagationcontext.py b/tests/test_propagationcontext.py index 43f712b38b..3606c5e9c1 100644 --- a/tests/test_propagationcontext.py +++ b/tests/test_propagationcontext.py @@ -131,7 +131,7 @@ def test_existing_sample_rand_kept(): def test_sample_rand_filled(parent_sampled, sample_rate, expected_interval): """When continuing a trace, we want to fill in the sample_rand value if it's missing.""" if sample_rate is not None: - sample_rate_str = f",sentry-sample_rate={sample_rate}" # noqa: E231 + sample_rate_str = f",sentry-sample_rate={sample_rate}" else: sample_rate_str = "" @@ -153,9 +153,7 @@ def mock_random_class(seed): } ) - assert ( - ctx.dynamic_sampling_context["sample_rand"] == f"{expected_interval[0]:.6f}" # noqa: E231 - ) + assert ctx.dynamic_sampling_context["sample_rand"] == f"{expected_interval[0]:.6f}" assert mock_randrange.call_count == 1 assert mock_randrange.call_args[0] == ( int(expected_interval[0] * 1000000), diff --git a/tests/test_utils.py b/tests/test_utils.py index d5b9713cce..8b39a1056e 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -485,7 +485,7 @@ def test_accepts_valid_sample_rate(rate): 1.231, # wrong value ], ) -def test_warns_on_invalid_sample_rate(rate, StringContaining): # noqa: N803 +def test_warns_on_invalid_sample_rate(rate, StringContaining): with mock.patch.object(logger, "warning", mock.Mock()): result = is_valid_sample_rate(rate, source="Testing") logger.warning.assert_any_call(StringContaining("Given sample rate is invalid")) diff --git a/tests/tracing/test_sample_rand.py b/tests/tracing/test_sample_rand.py index e9835d1de1..40f7431482 100644 --- a/tests/tracing/test_sample_rand.py +++ b/tests/tracing/test_sample_rand.py @@ -36,7 +36,7 @@ def test_deterministic_sampled(sentry_init, capture_events, sample_rate, sample_ with sentry_sdk.start_transaction() as transaction: assert ( transaction.get_baggage().sentry_items["sample_rand"] - == f"{sample_rand:.6f}" # noqa: E231 + == f"{sample_rand:.6f}" ) # Transaction event captured if sample_rand < sample_rate, indicating that @@ -65,7 +65,7 @@ def test_deterministic_sampled_span_streaming( ): with sentry_sdk.traces.start_span(name="span") as span: assert ( - span._get_baggage().sentry_items["sample_rand"] == f"{sample_rand:.6f}" # noqa: E231 + span._get_baggage().sentry_items["sample_rand"] == f"{sample_rand:.6f}" ) sentry_sdk.flush() @@ -82,7 +82,7 @@ def test_transaction_uses_incoming_sample_rand( """ Test that the transaction uses the sample_rand value from the incoming baggage. """ - baggage = Baggage(sentry_items={"sample_rand": f"{sample_rand:.6f}"}) # noqa: E231 + baggage = Baggage(sentry_items={"sample_rand": f"{sample_rand:.6f}"}) sentry_init(traces_sample_rate=sample_rate) events = capture_events() @@ -90,7 +90,7 @@ def test_transaction_uses_incoming_sample_rand( with sentry_sdk.start_transaction(baggage=baggage) as transaction: assert ( transaction.get_baggage().sentry_items["sample_rand"] - == f"{sample_rand:.6f}" # noqa: E231 + == f"{sample_rand:.6f}" ) # Transaction event captured if sample_rand < sample_rate, indicating that @@ -119,9 +119,7 @@ def test_segment_uses_incoming_sample_rand_span_streaming( ) with sentry_sdk.traces.start_span(name="span") as span: - assert ( - span._get_baggage().sentry_items["sample_rand"] == f"{sample_rand:.6f}" # noqa: E231 - ) + assert span._get_baggage().sentry_items["sample_rand"] == f"{sample_rand:.6f}" sentry_sdk.flush() diff --git a/tests/tracing/test_sampling.py b/tests/tracing/test_sampling.py index 62e861dc8b..2f1b670c3e 100644 --- a/tests/tracing/test_sampling.py +++ b/tests/tracing/test_sampling.py @@ -405,7 +405,7 @@ def mock_set_initial_sampling_decision(_, sampling_context): def test_passes_custom_sampling_context_from_start_transaction_to_traces_sampler( sentry_init, - DictionaryContaining, # noqa: N803 + DictionaryContaining, ): traces_sampler = mock.Mock() sentry_init(traces_sampler=traces_sampler) @@ -498,7 +498,7 @@ def test_sample_rate_affects_errors(sentry_init, capture_events): def test_warns_and_sets_sampled_to_false_on_invalid_traces_sampler_return_value( sentry_init, traces_sampler_return_value, - StringContaining, # noqa: N803 + StringContaining, ): sentry_init(traces_sampler=mock.Mock(return_value=traces_sampler_return_value)) @@ -521,7 +521,7 @@ def test_warns_and_sets_sampled_to_false_on_invalid_traces_sampler_return_value( def test_warns_and_sets_sampled_to_false_on_invalid_traces_sampler_return_value_span_streaming( sentry_init, traces_sampler_return_value, - StringContaining, # noqa: N803 + StringContaining, ): sentry_init( traces_sampler=mock.Mock(return_value=traces_sampler_return_value), diff --git a/tests/utils/test_contextvars.py b/tests/utils/test_contextvars.py index 50881314c1..95ae03fc42 100644 --- a/tests/utils/test_contextvars.py +++ b/tests/utils/test_contextvars.py @@ -12,7 +12,7 @@ def _run_contextvar_threaded_test(): # decided upon gevent on import. from sentry_sdk import utils - _, ContextVar = utils._get_contextvars() # noqa: N806 + _, ContextVar = utils._get_contextvars() ts = []