Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ select = [
"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
"PLC0415", # Import not at the top level of the file
"PT011", # pytest.raises() too broad
"PT012", # pytest.raises() block with more than one statement
"RUF100", # Unused noqa directive
"T20", # print() and pprint() calls
]

# Use ONLY the same ignores as the original flake8 config + compatibility for this codebase
Expand All @@ -317,6 +322,10 @@ ignore = [
"E721", # Use isinstance instead of type() == - existing pattern in this codebase
]

[tool.ruff.lint.per-file-ignores]
"scripts/**" = ["T20"]
"tests/**" = ["PLC0415", "T20"]

[tool.ruff.format]
# ruff format already excludes the same files as specified in extend-exclude
# Ensure Python 3.7 compatibility - avoid using Python 3.9+ syntax features
Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def check_uwsgi_thread_support() -> bool:
# --py-call-uwsgi-fork-hooks to force uWSGI to run regular cpython
# after-fork hooks that take care of cleaning up stale thread data.
try:
from uwsgi import opt # type: ignore
from uwsgi import opt # type: ignore # noqa: PLC0415
except ImportError:
return True

from sentry_sdk.consts import FALSE_VALUES
from sentry_sdk.consts import FALSE_VALUES # noqa: PLC0415

def enabled(option: str) -> bool:
value = opt.get(option, False)
Expand All @@ -61,7 +61,7 @@ def enabled(option: str) -> bool:
lazy_mode = enabled("lazy-apps") or enabled("lazy")

if lazy_mode and not threads_enabled:
from warnings import warn
from warnings import warn # noqa: PLC0415

warn(
Warning(
Expand All @@ -75,7 +75,7 @@ def enabled(option: str) -> bool:
return False

elif not lazy_mode and (not threads_enabled or not fork_hooks_on):
from warnings import warn
from warnings import warn # noqa: PLC0415

warn(
Warning(
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/_init_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def _record_lost_event(

# Setup Spotlight before creating batchers so _capture_envelope can use it.
# setup_spotlight handles all config/env var resolution per the SDK spec.
from sentry_sdk.spotlight import setup_spotlight
from sentry_sdk.spotlight import setup_spotlight # noqa: PLC0415

self.spotlight = setup_spotlight(self.options)
if self.spotlight is not None and not self.options["dsn"]:
Expand Down Expand Up @@ -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):
Expand Down
18 changes: 8 additions & 10 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -1423,18 +1423,16 @@ 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,
project_root: "Optional[str]" = None,
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,
Expand Down Expand Up @@ -1912,7 +1910,7 @@ def __init__(


def _get_default_options() -> "dict[str, Any]":
import inspect
import inspect # noqa: PLC0415

a = inspect.getfullargspec(ClientConstructor.__init__)
defaults = a.defaults or ()
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/crons/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
R = TypeVar("R")


class monitor: # noqa: N801
class monitor:
"""
Decorator/context manager to capture checkin events for a monitor.

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def iter_default_integrations(
with_auto_enabling_integrations: bool,
) -> "Iterator[Type[Integration]]":
"""Returns an iterator of the default integration classes:"""
from importlib import import_module
from importlib import import_module # noqa: PLC0415

if with_auto_enabling_integrations:
all_import_strings = integrations + auto_enabling_integrations
Expand Down Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/anthropic.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def setup_once() -> None:
AsyncMessageStream.close = _wrap_async_close(AsyncMessageStream.close) # type: ignore[method-assign]

try:
from functools import cached_property
from functools import cached_property # noqa: PLC0415
except ImportError:
return

Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
6 changes: 3 additions & 3 deletions sentry_sdk/integrations/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BeamIntegration(Integration):

@staticmethod
def setup_once() -> None:
from apache_beam.transforms.core import DoFn, ParDo # type: ignore
from apache_beam.transforms.core import DoFn, ParDo # type: ignore # noqa: PLC0415

ignore_logger("root")
ignore_logger("bundle_processor.create")
Expand Down Expand Up @@ -94,11 +94,11 @@ def _inspect(self: "Any") -> "Any":
# getfullargspec is deprecated in more recent beam versions and get_function_args_defaults
# (which uses Signatures internally) should be used instead.
try:
from apache_beam.transforms.core import get_function_args_defaults
from apache_beam.transforms.core import get_function_args_defaults # noqa: PLC0415

return get_function_args_defaults(process_func)
except ImportError:
from apache_beam.typehints.decorators import getfullargspec # type: ignore
from apache_beam.typehints.decorators import getfullargspec # type: ignore # noqa: PLC0415

return getfullargspec(process_func)

Expand Down
6 changes: 3 additions & 3 deletions sentry_sdk/integrations/celery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def _inner(*args: "Any", **kwargs: "Any") -> "Any":


def _patch_build_tracer() -> None:
import celery.app.trace as trace # type: ignore
import celery.app.trace as trace # type: ignore # noqa: PLC0415

original_build_tracer = trace.build_tracer

Expand Down Expand Up @@ -527,15 +527,15 @@ def _patch_task_apply_async() -> None:


def _patch_celery_send_task() -> None:
from celery import Celery
from celery import Celery # noqa: PLC0415

Celery.send_task = _wrap_task_run(Celery.send_task)


def _patch_worker_exit() -> None:
# Need to flush queue before worker shutdown because a crashing worker will
# call os._exit
from billiard.pool import Worker # type: ignore
from billiard.pool import Worker # type: ignore # noqa: PLC0415

original_workloop = Worker.workloop

Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/celery/beat.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _wrap_beat_scheduler(
if already_patched:
return original_function

from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.celery import CeleryIntegration # noqa: PLC0415

def sentry_patched_scheduler(*args: "Any", **kwargs: "Any") -> None:
integration = sentry_sdk.get_client().get_integration(CeleryIntegration)
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/chalice.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def setup_once() -> None:
if version < (1, 20):
old_get_view_function_response = Chalice._get_view_function_response
else:
from chalice.app import RestAPIEventHandler
from chalice.app import RestAPIEventHandler # noqa: PLC0415

old_get_view_function_response = (
RestAPIEventHandler._get_view_function_response
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/cloud_resource_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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/
Expand Down
Loading
Loading