Skip to content
Merged
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
6 changes: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
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
2 changes: 1 addition & 1 deletion sentry_sdk/client.py
Original file line number Diff line number Diff line change
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
16 changes: 7 additions & 9 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
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
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/__init__.py
Original file line number Diff line number Diff line change
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/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
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
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/litestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/redis/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/rust_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
58 changes: 29 additions & 29 deletions sentry_sdk/integrations/spark/spark_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()}
Expand All @@ -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())

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

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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"]
Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<epoch>[0-9]+)!)? # epoch
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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/<number>, return status code <number>.
# Otherwise return a 200 response.
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/aiohttp/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading
Loading