Skip to content

ci(ruff): Enable rules for inline imports, prints, unused noqa and pytest.raises - #8280

Closed
sentry-junior[bot] wants to merge 1 commit into
masterfrom
ci/ruff-extra-rules
Closed

sentry-junior[bot] wants to merge 1 commit into
masterfrom
ci/ruff-extra-rules

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Description

Turns on ruff rules for problems we currently catch by hand in review:

  • PLC0415: imports inside functions, which AGENTS.md asks us to avoid. Only applies to sentry_sdk.
  • T20: print() calls. Only applies to sentry_sdk; tests and scripts are excluded.
  • PT011: pytest.raises() with an exception type that's too broad and no match=.
  • PT012: a pytest.raises() block with more than one statement, which hides which line actually raised.
  • RUF100: noqa comments that don't suppress anything.

Existing violations get a # noqa: <code> comment, so only new code has to follow the rules. That's 105 inline imports in the SDK and 63 pytest.raises cases in tests. Many of the inline imports are intentional (optional deps, Django settings), so a new one now needs an explicit noqa that a reviewer can see.

RUF100 also removes 189 noqa comments for rules ruff doesn't enable, mostly N8xx, E231 and B0xx codes left over from the flake8 plugins.

All code changes are comments only; nothing in the code itself changes. Most of the 97 files are just added or removed noqa comments.

Open question: should the flake8-era N8xx/B0xx comments go away, as they do here? The alternative is keeping them as markers in case we enable those rule families later.

via @sentrivana.

--

View Session [Sentry]

…test.raises

Turn on PLC0415, T20, RUF100, PT011 and PT012. Existing violations get
a noqa comment so new code is checked without a big cleanup first.
RUF100 removes the noqa comments for rules that ruff doesn't enable,
most of them left over from the flake8 plugins.

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

sentry-junior Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Split into one PR per rule. They're stacked because each one edits the same select list: #8282 (RUF100) → #8283 (T20) → #8285 (PLC0415) → #8286 (PT011) → #8287 (PT012). Closing this one in favor of the stack.

@sentry-junior sentry-junior Bot closed this Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Results 📊

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

📊 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 96.50% (138 of 143 changed executable lines covered; target 80%).
Project statement coverage is 90.25% (up 0.03 percentage points from base (ae73d8c) to head (a7426c7)).

Changed files with executable lines (48)
File Patch coverage Changed executable lines
sentry_sdk/integrations/django/init.py 94.12% 16/17 covered; missed: 844
sentry_sdk/integrations/gcp.py 0.00% 0/1 covered; missed: 203
sentry_sdk/integrations/openai_agents/patches/error_tracing.py 50.00% 1/2 covered; missed: 36
sentry_sdk/integrations/spark/spark_driver.py 96.97% 32/33 covered; missed: 95
sentry_sdk/spotlight.py 0.00% 0/1 covered; missed: 121
sentry_sdk/_compat.py 100.00% 4/4 covered
sentry_sdk/client.py 100.00% 1/1 covered
sentry_sdk/consts.py 100.00% 1/1 covered
sentry_sdk/crons/decorator.py 100.00% 1/1 covered
sentry_sdk/integrations/init.py 100.00% 2/2 covered
sentry_sdk/integrations/anthropic.py 100.00% 1/1 covered
sentry_sdk/integrations/asgi.py 100.00% 1/1 covered
sentry_sdk/integrations/beam.py 100.00% 3/3 covered
sentry_sdk/integrations/celery/init.py 100.00% 3/3 covered
sentry_sdk/integrations/celery/beat.py 100.00% 1/1 covered
sentry_sdk/integrations/chalice.py 100.00% 1/1 covered
sentry_sdk/integrations/cloud_resource_context.py 100.00% 2/2 covered
sentry_sdk/integrations/django/asgi.py 100.00% 5/5 covered
sentry_sdk/integrations/django/caching.py 100.00% 4/4 covered
sentry_sdk/integrations/django/middleware.py 100.00% 2/2 covered
sentry_sdk/integrations/django/signals_handlers.py 100.00% 1/1 covered
sentry_sdk/integrations/django/tasks.py 100.00% 1/1 covered
sentry_sdk/integrations/django/templates.py 100.00% 3/3 covered
sentry_sdk/integrations/django/views.py 100.00% 4/4 covered
sentry_sdk/integrations/flask.py 100.00% 1/1 covered
sentry_sdk/integrations/grpc/init.py 100.00% 1/1 covered
sentry_sdk/integrations/openai.py 100.00% 1/1 covered
sentry_sdk/integrations/pydantic_ai/init.py 100.00% 1/1 covered
sentry_sdk/integrations/pydantic_ai/patches/tools.py 100.00% 2/2 covered
sentry_sdk/integrations/pydantic_ai/utils.py 100.00% 1/1 covered
sentry_sdk/integrations/pyramid.py 100.00% 1/1 covered
sentry_sdk/integrations/redis/init.py 100.00% 1/1 covered
sentry_sdk/integrations/redis/_async_common.py 100.00% 2/2 covered
sentry_sdk/integrations/redis/_sync_common.py 100.00% 2/2 covered
sentry_sdk/integrations/redis/rb.py 100.00% 1/1 covered
sentry_sdk/integrations/redis/redis.py 100.00% 3/3 covered
sentry_sdk/integrations/redis/redis_cluster.py 100.00% 3/3 covered
sentry_sdk/integrations/redis/redis_py_cluster_legacy.py 100.00% 1/1 covered
sentry_sdk/integrations/rust_tracing.py 100.00% 1/1 covered
sentry_sdk/integrations/spark/spark_worker.py 100.00% 3/3 covered
sentry_sdk/integrations/starlette.py 100.00% 2/2 covered
sentry_sdk/integrations/threading.py 100.00% 2/2 covered
sentry_sdk/scope.py 100.00% 1/1 covered
sentry_sdk/traces.py 100.00% 2/2 covered
sentry_sdk/tracing.py 100.00% 1/1 covered
sentry_sdk/tracing_utils.py 100.00% 2/2 covered
sentry_sdk/transport.py 100.00% 2/2 covered
sentry_sdk/utils.py 100.00% 11/11 covered
Coverage diff
@@            Coverage Diff             @@
##        master     #8280       +/-##
==========================================
+ Coverage    90.22%    90.25%    +0.03%
==========================================
  Files          203       203         —
  Tracked lines     27335     27335         —
  Branches     10246     10246         —
==========================================
+ Hits         24661     24669        +8
+ Misses        2674      2666        -8
+ Partials      1558      1557        -1

Generated by Coverage Action

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.

1 participant