Skip to content

ci(ruff): Enable RUF100 for unused noqa directives - #8282

Merged
sentrivana merged 4 commits into
masterfrom
ci/ruff-unused-noqa
Nov 16, 2026
Merged

sentrivana merged 4 commits into
masterfrom
ci/ruff-unused-noqa

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Turns on ruff's RUF100, which flags noqa comments that don't suppress anything, so stale suppressions can't pile up. It also removes the 189 that exist today, most of them N8xx, E231 and B0xx codes left over from the flake8 plugins, which ruff doesn't enable here. The leftover B/N ignores and notes in pyproject.toml go too. Only comments and config change; some lines got joined by ruff format once their comments were gone.

Each ruff-rule PR (#8282, #8283, #8285, #8286, #8287) targets master on its own. They all add a line to the same select list in pyproject.toml, so whichever merges first leaves the others with a small conflict there to resolve.

via @sentrivana.

--

View Session [Sentry]

Remove noqa comments that no longer suppress anything, most of them
for pep8-naming and bugbear codes left over from the flake8 plugins,
which ruff doesn't enable here.

Co-Authored-By: Ivana Kellyer <131587164+sentrivana@users.noreply.github.com>
@sentrivana

Copy link
Copy Markdown
Collaborator

@sentry-junior Regarding "Open question: should the flake8-era N8xx/B0xx comments be deleted, or kept as markers in case those rule groups get turned on later?" They should be deleted. If you haven't deleted them yet, do it in this PR please

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Results 📊

✅ 139266 passed | ⏭️ 7853 skipped | Total: 147119 | Pass Rate: 94.66% | Execution Time: 451m 4s

📊 Comparison with Base Branch

Metric Change
Total Tests —
Passed Tests —
Failed Tests —
Skipped Tests —

✨ Test counts unchanged from base.

All tests are passing successfully.

✅ Patch coverage is 100.00% (40 of 40 changed executable lines covered; target 80%).
Project statement coverage is 90.21% (down 0.03 percentage points from base (ddd4948) to head (1cef931)).

Changed files with executable lines (10)
File Patch coverage Changed executable lines
sentry_sdk/crons/decorator.py 100.00% 1/1 covered
sentry_sdk/integrations/init.py 100.00% 1/1 covered
sentry_sdk/integrations/asgi.py 100.00% 1/1 covered
sentry_sdk/integrations/cloud_resource_context.py 100.00% 2/2 covered
sentry_sdk/integrations/redis/redis.py 100.00% 1/1 covered
sentry_sdk/integrations/rust_tracing.py 100.00% 1/1 covered
sentry_sdk/integrations/spark/spark_driver.py 100.00% 28/28 covered
sentry_sdk/integrations/threading.py 100.00% 1/1 covered
sentry_sdk/tracing_utils.py 100.00% 2/2 covered
sentry_sdk/utils.py 100.00% 2/2 covered
Coverage diff
@@            Coverage Diff             @@
##        master     #8282       +/-##
==========================================
- Coverage    90.24%    90.21%    -0.03%
==========================================
  Files          203       203         —
  Tracked lines     27335     27335         —
  Branches     10246     10246         —
==========================================
- Hits         24668     24660        -8
- Misses        2667      2675        +8
- Partials      1558      1559        +1

Generated by Coverage Action

Drop the N806 marker inside parse_version's verbose regex (it was a
regex comment, so the pattern is unchanged), the B014/N812/N804
ignores, and the note about B and N rules. Neither rule group is
selected.
@sentry-junior

sentry-junior Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Removed. The first commit already dropped the flake8-era noqa codes that RUF100 flagged. f6f8105 removes the rest:

  • # noqa: N806 inside parse_version's VERSION_PATTERN. It sits inside the verbose regex string, so RUF100 couldn't see it, and re.VERBOSE treats it as a regex comment. The pattern doesn't change.
  • The B014, N812 and N804 entries in ignore, plus the note about B and N rules in select. Neither rule group is selected, so they have no effect.

No N or B codes are left in the repo.

@sentrivana
sentrivana enabled auto-merge (squash) November 16, 2026 10:12
sentrivana added a commit that referenced this pull request Nov 16, 2026
### Description

Turns on ruff's `T20`, which flags `print()` and `pprint()` calls. The
SDK runs inside users' apps, so a stray debug `print()` ends up in their
output; we should log through the SDK logger instead. `sentry_sdk` has
none today, so this is config only. Tests and scripts are excluded via
`per-file-ignores` because they print on purpose.

Each ruff-rule PR (#8282, #8283, #8285, #8286, #8287) targets `master`
on its own. They all add a line to the same `select` list in
`pyproject.toml`, so whichever merges first leaves the others with a
small conflict there to resolve.

<!-- junior-request-attribution:start -->
via @sentrivana.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0CAA8NNBE3%3A1794392136.309249 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Ivana Kellyer <131587164+sentrivana@users.noreply.github.com>
sentrivana added a commit that referenced this pull request Nov 16, 2026
### Description

Turns on ruff's `PT011`, which flags `pytest.raises()` with a broad
exception type such as `ValueError` or `Exception` and no `match=`.
Without `match=`, a test can pass on the wrong error.

The 27 existing offenders are fixed rather than ignored. Most get a
`match=` with the expected message. Two get a narrower exception type
(`CannotSendRequest` in the httplib test, `ZeroDivisionError` in a
skipped celery test), and `test_get_error_message` no longer misuses
`pytest.raises()` as an attribute holder.

Each ruff-rule PR (#8282, #8283, #8285, #8286, #8287) targets `master`
on its own. They all add a line to the same `select` list in
`pyproject.toml`, so whichever merges first leaves the others with a
small conflict there to resolve.

<!-- junior-request-attribution:start -->
via @sentrivana.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0CAA8NNBE3%3A1794392136.309249 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Ivana Kellyer <131587164+sentrivana@users.noreply.github.com>
Co-authored-by: Ivana Kellyer <ivana.kellyer@sentry.io>
# Conflicts:
#	pyproject.toml
#	tests/integrations/celery/test_celery.py
#	tests/integrations/stdlib/test_httplib.py
@sentrivana
sentrivana merged commit 4c1a136 into master Nov 16, 2026
174 checks passed
@sentrivana
sentrivana deleted the ci/ruff-unused-noqa branch November 16, 2026 10:42
sentrivana added a commit that referenced this pull request Nov 16, 2026
### Description

Turns on ruff's `PLC0415`, which flags imports that aren't at the top
level of the file. This enforces the top-level-imports guideline in
`AGENTS.md`, which reviewers currently check by hand. The rule covers
`sentry_sdk` only; tests are excluded.

16 existing inline imports didn't need to be inline, so they're now at
the top level or in an existing module-level import. The other 89 are
intentional (optional deps, version checks, circular imports, Django)
and get a `# noqa: PLC0415` comment, so any new inline import needs the
same explicit marker.

Each ruff-rule PR (#8282, #8283, #8285, #8286, #8287) targets `master`
on its own. They all add a line to the same `select` list in
`pyproject.toml`, so whichever merges first leaves the others with a
small conflict there to resolve.

<!-- junior-request-attribution:start -->
via @sentrivana.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0CAA8NNBE3%3A1794392136.309249 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Ivana Kellyer <131587164+sentrivana@users.noreply.github.com>
@linear-code

linear-code Bot commented Nov 17, 2026

Copy link
Copy Markdown

PY-3083

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants