Skip to content

Commit 8a4ea04

Browse files
lobsterkatieandrewshie-sentry
authored andcommitted
chore(various): Fix linter warnings (#82494)
This fixes a number of small issues my linter has been yelling at me about, which I've come across in the last handful of weeks - things like unused variables, shadowing built-ins, etc. No behavior changes just tiny refactors to clear out some noise.
1 parent e999f0f commit 8a4ea04

File tree

12 files changed

+69
-79
lines changed

12 files changed

+69
-79
lines changed

src/sentry/event_manager.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2376,15 +2376,15 @@ def save_attachment(
23762376
return
23772377
from sentry import ratelimits as ratelimiter
23782378

2379-
is_limited, num_requests, reset_time = ratelimiter.backend.is_limited_with_value(
2379+
is_limited, _, _ = ratelimiter.backend.is_limited_with_value(
23802380
key="event_attachment.save_per_sec",
23812381
limit=options.get("sentry.save-event-attachments.project-per-sec-limit"),
23822382
project=project,
23832383
window=1,
23842384
)
23852385
rate_limit_tag = "per_sec"
23862386
if not is_limited:
2387-
is_limited, num_requests, reset_time = ratelimiter.backend.is_limited_with_value(
2387+
is_limited, _, _ = ratelimiter.backend.is_limited_with_value(
23882388
key="event_attachment.save_5_min",
23892389
limit=options.get("sentry.save-event-attachments.project-per-5-minute-limit"),
23902390
project=project,

src/sentry/grouping/enhancer/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def loads(cls, data) -> Enhancements:
265265

266266
@classmethod
267267
@sentry_sdk.tracing.trace
268-
def from_config_string(self, s, bases=None, id=None) -> Enhancements:
268+
def from_config_string(cls, s, bases=None, id=None) -> Enhancements:
269269
rust_enhancements = parse_rust_enhancements("config_string", s)
270270

271271
rules = parse_enhancements(s)

src/sentry/grouping/enhancer/actions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def is_updater(self) -> bool:
5656
def _from_config_structure(cls, val, version: int):
5757
if isinstance(val, list):
5858
return VarAction(val[0], val[1])
59-
flag, range = REVERSE_ACTION_FLAGS[val >> ACTION_BITSIZE]
60-
return FlagAction(ACTIONS[val & 0xF], flag, range)
59+
flag, range_direction = REVERSE_ACTION_FLAGS[val >> ACTION_BITSIZE]
60+
return FlagAction(ACTIONS[val & 0xF], flag, range_direction)
6161

6262

6363
class FlagAction(EnhancementAction):

src/sentry/grouping/fingerprinting/__init__.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -452,20 +452,13 @@ def _positive_match(self, values: dict[str, Any]) -> bool:
452452
value = values.get(self.key)
453453
if value is None:
454454
return False
455-
elif self.key == "package":
455+
elif self.key in ["package", "release"]:
456456
if self._positive_path_match(value):
457457
return True
458-
elif self.key == "family":
458+
elif self.key in ["family", "sdk"]:
459459
flags = self.pattern.split(",")
460460
if "all" in flags or value in flags:
461461
return True
462-
elif self.key == "sdk":
463-
flags = self.pattern.split(",")
464-
if "all" in flags or value in flags:
465-
return True
466-
elif self.key == "release":
467-
if self._positive_path_match(value):
468-
return True
469462
elif self.key == "app":
470463
ref_val = bool_from_string(self.pattern)
471464
if ref_val is not None and ref_val == value:
@@ -591,7 +584,7 @@ def visit_fingerprinting_rules(
591584
in_header = True
592585
for child in children:
593586
if isinstance(child, str):
594-
if in_header and child[:2] == "##":
587+
if in_header and child.startswith("##"):
595588
changelog.append(child[2:].rstrip())
596589
else:
597590
in_header = False

src/sentry/grouping/strategies/legacy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ def is_recursion_legacy(frame1: Frame, frame2: Frame) -> bool:
111111
def remove_module_outliers_legacy(module: str, platform: str) -> tuple[str, str | None]:
112112
"""Remove things that augment the module but really should not."""
113113
if platform == "java":
114-
if module[:35] == "sun.reflect.GeneratedMethodAccessor":
114+
if module.startswith("sun.reflect.GeneratedMethodAccessor"):
115115
return "sun.reflect.GeneratedMethodAccessor", "removed reflection marker"
116-
if module[:44] == "jdk.internal.reflect.GeneratedMethodAccessor":
116+
if module.startswith("jdk.internal.reflect.GeneratedMethodAccessor"):
117117
return "jdk.internal.reflect.GeneratedMethodAccessor", "removed reflection marker"
118118
old_module = module
119119
module = _java_reflect_enhancer_re.sub(r"\1<auto>", module)

src/sentry/grouping/strategies/newstyle.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ def get_filename_component(
152152
new_filename = _java_assist_enhancer_re.sub(r"\1<auto>", filename)
153153
if new_filename != filename:
154154
filename_component.update(values=[new_filename], hint="cleaned javassist parts")
155-
filename = new_filename
156155

157156
return filename_component
158157

@@ -176,11 +175,11 @@ def get_module_component(
176175
elif platform == "java":
177176
if "$$Lambda$" in module:
178177
module_component.update(contributes=False, hint="ignored java lambda")
179-
if module[:35] == "sun.reflect.GeneratedMethodAccessor":
178+
if module.startswith("sun.reflect.GeneratedMethodAccessor"):
180179
module_component.update(
181180
values=["sun.reflect.GeneratedMethodAccessor"], hint="removed reflection marker"
182181
)
183-
elif module[:44] == "jdk.internal.reflect.GeneratedMethodAccessor":
182+
elif module.startswith("jdk.internal.reflect.GeneratedMethodAccessor"):
184183
module_component.update(
185184
values=["jdk.internal.reflect.GeneratedMethodAccessor"],
186185
hint="removed reflection marker",

src/sentry/utils/tag_normalization.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def normalize_sdk_tag(tag: str) -> str:
9292

9393
# collapse tags other than JavaScript / Native to their top-level SDK
9494

95-
if not tag.split(".")[1] in {"javascript", "native"}:
95+
if tag.split(".")[1] not in {"javascript", "native"}:
9696
tag = ".".join(tag.split(".", 2)[0:2])
9797

9898
if tag.split(".")[1] == "native":

tests/sentry/event_manager/test_event_manager.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ def test_group_release_no_env(self) -> None:
11211121
).exists()
11221122

11231123
# ensure we're not erroring on second creation
1124-
event = self.make_release_event("1.0", project_id)
1124+
self.make_release_event("1.0", project_id)
11251125

11261126
def test_group_release_with_env(self) -> None:
11271127
manager = EventManager(make_event(release="1.0", environment="prod", event_id="a" * 32))
@@ -1891,9 +1891,7 @@ def test_throws_when_matches_discarded_hash(self) -> None:
18911891
with self.feature("organizations:event-attachments"):
18921892
with self.tasks():
18931893
with pytest.raises(HashDiscarded):
1894-
event = manager.save(
1895-
self.project.id, cache_key=cache_key, has_attachments=True
1896-
)
1894+
manager.save(self.project.id, cache_key=cache_key, has_attachments=True)
18971895

18981896
assert mock_track_outcome.call_count == 3
18991897

tests/sentry/grouping/ingest/test_seer.py

+38-38
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,19 @@ def setUp(self) -> None:
240240

241241
@patch("sentry.grouping.ingest.seer.get_similarity_data_from_seer", return_value=[])
242242
def test_sends_expected_data_to_seer(self, mock_get_similarity_data: MagicMock) -> None:
243-
type = "FailedToFetchError"
244-
value = "Charlie didn't bring the ball back"
245-
context_line = f"raise {type}('{value}')"
243+
error_type = "FailedToFetchError"
244+
error_value = "Charlie didn't bring the ball back"
245+
context_line = f"raise {error_type}('{error_value}')"
246246
new_event = Event(
247247
project_id=self.project.id,
248248
event_id="12312012112120120908201304152013",
249249
data={
250-
"title": f"{type}('{value}')",
250+
"title": f"{error_type}('{error_value}')",
251251
"exception": {
252252
"values": [
253253
{
254-
"type": type,
255-
"value": value,
254+
"type": error_type,
255+
"value": error_value,
256256
"stacktrace": {
257257
"frames": [
258258
{
@@ -275,7 +275,7 @@ def test_sends_expected_data_to_seer(self, mock_get_similarity_data: MagicMock)
275275
"event_id": new_event.event_id,
276276
"hash": new_event.get_primary_hash(),
277277
"project_id": self.project.id,
278-
"stacktrace": f'{type}: {value}\n File "dogpark.py", function play_fetch\n {context_line}',
278+
"stacktrace": f'{error_type}: {error_value}\n File "dogpark.py", function play_fetch\n {context_line}',
279279
"exception_type": "FailedToFetchError",
280280
"k": 1,
281281
"referrer": "ingest",
@@ -353,19 +353,19 @@ def test_returns_no_grouphash_and_empty_metadata_if_empty_stacktrace(
353353
def test_too_many_frames(
354354
self, mock_metrics: Mock, mock_record_did_call_seer: MagicMock
355355
) -> None:
356-
type = "FailedToFetchError"
357-
value = "Charlie didn't bring the ball back"
358-
context_line = f"raise {type}('{value}')"
356+
error_type = "FailedToFetchError"
357+
error_value = "Charlie didn't bring the ball back"
358+
context_line = f"raise {error_type}('{error_value}')"
359359
new_event = Event(
360360
project_id=self.project.id,
361361
event_id="22312012112120120908201304152013",
362362
data={
363-
"title": f"{type}('{value}')",
363+
"title": f"{error_type}('{error_value}')",
364364
"exception": {
365365
"values": [
366366
{
367-
"type": type,
368-
"value": value,
367+
"type": error_type,
368+
"value": error_value,
369369
"stacktrace": {
370370
"frames": [
371371
{
@@ -401,19 +401,19 @@ def test_too_many_frames(
401401

402402
@patch("sentry.seer.similarity.utils.record_did_call_seer_metric")
403403
def test_too_many_frames_allowed_platform(self, mock_record_did_call_seer: MagicMock) -> None:
404-
type = "FailedToFetchError"
405-
value = "Charlie didn't bring the ball back"
406-
context_line = f"raise {type}('{value}')"
404+
error_type = "FailedToFetchError"
405+
error_value = "Charlie didn't bring the ball back"
406+
context_line = f"raise {error_type}('{error_value}')"
407407
new_event = Event(
408408
project_id=self.project.id,
409409
event_id="22312012112120120908201304152013",
410410
data={
411-
"title": f"{type}('{value}')",
411+
"title": f"{error_type}('{error_value}')",
412412
"exception": {
413413
"values": [
414414
{
415-
"type": type,
416-
"value": value,
415+
"type": error_type,
416+
"value": error_value,
417417
"stacktrace": {
418418
"frames": [
419419
{
@@ -453,19 +453,19 @@ def test_valid_maybe_check_seer_for_matching_group_hash(
453453
) -> None:
454454
self.project.update_option("sentry:similarity_backfill_completed", int(time()))
455455

456-
type = "FailedToFetchError"
457-
value = "Charlie didn't bring the ball back"
458-
context_line = f"raise {type}('{value}')"
456+
error_type = "FailedToFetchError"
457+
error_value = "Charlie didn't bring the ball back"
458+
context_line = f"raise {error_type}('{error_value}')"
459459
new_event = Event(
460460
project_id=self.project.id,
461461
event_id="12312012112120120908201304152013",
462462
data={
463-
"title": f"{type}('{value}')",
463+
"title": f"{error_type}('{error_value}')",
464464
"exception": {
465465
"values": [
466466
{
467-
"type": type,
468-
"value": value,
467+
"type": error_type,
468+
"value": error_value,
469469
"stacktrace": {
470470
"frames": [
471471
{
@@ -494,7 +494,7 @@ def test_valid_maybe_check_seer_for_matching_group_hash(
494494
"event_id": new_event.event_id,
495495
"hash": new_event.get_primary_hash(),
496496
"project_id": self.project.id,
497-
"stacktrace": f'{type}: {value}\n File "dogpark.py", function play_fetch\n {context_line}',
497+
"stacktrace": f'{error_type}: {error_value}\n File "dogpark.py", function play_fetch\n {context_line}',
498498
"exception_type": "FailedToFetchError",
499499
"k": 1,
500500
"referrer": "ingest",
@@ -513,19 +513,19 @@ def test_too_many_frames_maybe_check_seer_for_matching_group_hash(
513513
) -> None:
514514
self.project.update_option("sentry:similarity_backfill_completed", int(time()))
515515

516-
type = "FailedToFetchError"
517-
value = "Charlie didn't bring the ball back"
518-
context_line = f"raise {type}('{value}')"
516+
error_type = "FailedToFetchError"
517+
error_value = "Charlie didn't bring the ball back"
518+
context_line = f"raise {error_type}('{error_value}')"
519519
new_event = Event(
520520
project_id=self.project.id,
521521
event_id="22312012112120120908201304152013",
522522
data={
523-
"title": f"{type}('{value}')",
523+
"title": f"{error_type}('{error_value}')",
524524
"exception": {
525525
"values": [
526526
{
527-
"type": type,
528-
"value": value,
527+
"type": error_type,
528+
"value": error_value,
529529
"stacktrace": {
530530
"frames": [
531531
{
@@ -572,19 +572,19 @@ def test_too_many_frames_maybe_check_seer_for_matching_group_hash_bypassed_platf
572572
) -> None:
573573
self.project.update_option("sentry:similarity_backfill_completed", int(time()))
574574

575-
type = "FailedToFetchError"
576-
value = "Charlie didn't bring the ball back"
577-
context_line = f"raise {type}('{value}')"
575+
error_type = "FailedToFetchError"
576+
error_value = "Charlie didn't bring the ball back"
577+
context_line = f"raise {error_type}('{error_value}')"
578578
new_event = Event(
579579
project_id=self.project.id,
580580
event_id="22312012112120120908201304152013",
581581
data={
582-
"title": f"{type}('{value}')",
582+
"title": f"{error_type}('{error_value}')",
583583
"exception": {
584584
"values": [
585585
{
586-
"type": type,
587-
"value": value,
586+
"type": error_type,
587+
"value": error_value,
588588
"stacktrace": {
589589
"frames": [
590590
{

tests/sentry/grouping/test_parameterization.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ def test_parameterize_regex_experiment():
241241
regex_pattern_keys=(),
242242
experiments=(FooExperiment,),
243243
)
244-
input = "blah foobarbaz fooooo"
245-
normalized = parameterizer.parameterize_all(input)
244+
input_str = "blah foobarbaz fooooo"
245+
normalized = parameterizer.parameterize_all(input_str)
246246
assert normalized == "blah <foo>barbaz <foo>ooo"
247247
assert len(parameterizer.get_successful_experiments()) == 1
248248
assert parameterizer.get_successful_experiments()[0] == FooExperiment
@@ -261,9 +261,9 @@ def test_parameterize_regex_experiment_cached_compiled():
261261
regex_pattern_keys=(),
262262
experiments=(FooExperiment,),
263263
)
264-
input = "blah foobarbaz fooooo"
265-
_ = parameterizer.parameterize_all(input)
266-
_ = parameterizer.parameterize_all(input)
264+
input_str = "blah foobarbaz fooooo"
265+
_ = parameterizer.parameterize_all(input_str)
266+
_ = parameterizer.parameterize_all(input_str)
267267

268268
mocked_pattern.assert_called_once()
269269

tests/sentry/issues/endpoints/test_group_similar_issues_embeddings.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -686,15 +686,15 @@ def test_obeys_useReranking_query_param(self, mock_seer_request: mock.MagicMock)
686686
mock_seer_request.reset_mock()
687687

688688
def test_too_many_system_frames(self) -> None:
689-
type = "FailedToFetchError"
690-
value = "Charlie didn't bring the ball back"
691-
context_line = f"raise {type}('{value}')"
689+
error_type = "FailedToFetchError"
690+
error_value = "Charlie didn't bring the ball back"
691+
context_line = f"raise {error_type}('{error_value}')"
692692
error_data = {
693693
"exception": {
694694
"values": [
695695
{
696-
"type": type,
697-
"value": value,
696+
"type": error_type,
697+
"value": error_value,
698698
"stacktrace": {
699699
"frames": [
700700
{
@@ -719,15 +719,15 @@ def test_too_many_system_frames(self) -> None:
719719
assert response.data == []
720720

721721
def test_no_filename_or_module(self) -> None:
722-
type = "FailedToFetchError"
723-
value = "Charlie didn't bring the ball back"
724-
context_line = f"raise {type}('{value}')"
722+
error_type = "FailedToFetchError"
723+
error_value = "Charlie didn't bring the ball back"
724+
context_line = f"raise {error_type}('{error_value}')"
725725
error_data = {
726726
"exception": {
727727
"values": [
728728
{
729-
"type": type,
730-
"value": value,
729+
"type": error_type,
730+
"value": error_value,
731731
"stacktrace": {
732732
"frames": [
733733
{

tests/sentry/monitors/tasks/test_detect_broken_monitor_envs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def test_does_not_create_broken_detection_insufficient_duration(self):
130130
grouphash=hash_from_values([uuid.uuid4()]),
131131
)
132132

133-
for i in range(4):
133+
for _ in range(4):
134134
MonitorCheckIn.objects.create(
135135
monitor=monitor,
136136
monitor_environment=monitor_environment,

0 commit comments

Comments
 (0)