Skip to content

ref(typing): Upgrade mypy to 1.20.1#113419

Merged
JoshFerge merged 7 commits into
masterfrom
joshferge/ref/upgrade-mypy-to-1-20-1
Apr 24, 2026
Merged

ref(typing): Upgrade mypy to 1.20.1#113419
JoshFerge merged 7 commits into
masterfrom
joshferge/ref/upgrade-mypy-to-1-20-1

Conversation

@JoshFerge

@JoshFerge JoshFerge commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Bumps the mypy pin to 1.20.1. Prep PRs for the bulk class-level-attribute fixes have already merged; what remains here is the pin bump, the GroupType ClassVar + __init_subclass__ migration, a handful of small typing cleanups, and targeted # type: ignore comments for cases that will get proper fixes in the follow-up PRs below.

Prep PRs (already merged)

What's in this PR

  • Bump mypy>=1.19.1mypy>=1.20.1 (+ uv.lock)
  • Drop the now-stale kombu.* entry from [[tool.mypy.overrides]]
  • src/sentry/issues/grouptype.py — convert GroupType fields to ClassVar and move the category-validation check from the dead __post_init__ into __init_subclass__. Plus the corresponding test updates in tests/sentry/issues/test_grouptype.py and tests/sentry/workflow_engine/endpoints/test_validators.py.
  • Small typing fixes that don't change runtime behavior:
    • digests/backends/base.py — widen options map to Mapping[str, Any]
    • discover/compare_timeseries.py — heterogeneous mismatches dict typed as dict[int, dict[str, Any]]
    • explore/endpoints/explore_saved_queries.py — drop unused # type: ignore
    • tests/sentry/incidents/test_logic.py — stringify both sides of the target_identifier comparison so mypy stops flagging it as unreachable
  • Targeted # type: ignore on six files where the proper fix is being landed as a follow-up PR (see below)
  • .github/workflows/scripts/bootstrap-snuba.py# type: ignore[arg-type] on int(workers_str) (single-file mypy can't see through sys.exit; follow-up can replace with NoReturn)

Follow-up PRs (drafts, based on this branch)

Each one removes one of the # type: ignore comments and applies the proper fix. They'll merge after this lands.

Performance

version cold warm
1.19.1 49.22s 17.82s
1.20.1 39.04s 5.73s

CI expectation

  • mypy job: clean (0 errors)
  • uv jobs: resolve against pypi.devinfra.sentry.io (1.20.1 has been published there)

Bump the mypy pin to 1.20.1 and fix the bulk of new type-check failures.

1.20.1 adds a stricter check for accessing instance-only attributes on a
class object. Several class-config patterns in the codebase (RegressionDetector,
GroupType, AttributeHandler, ReplayGroupTypeDefaults) declared configuration
fields as dataclass instance attributes but only ever accessed them via the
class. Convert those to ClassVar so access through the class is valid and drop
the no-op @DataClass(frozen=True) decorators.

The GroupType category validation that previously lived in __post_init__ (dead
code — no one instantiated GroupType) moves into __init_subclass__ so it still
runs at subclass-definition time.

Also addresses:
- Incorrect GroupStatus annotation where int is passed in practice
  (fetch_alert_threshold, fetch_resolve_threshold, from_workflow_engine_models,
  build_alert_context)
- Redundant casts in search/eap and search/events builders
- Unused kombu.* mypy override
- Unused type: ignore comments
- Mapping type fix in digests/backends/base.py
- None-narrowing fix in auth/access.from_auth
- None guard in reconnectingmemcache

Cuts the full-repo mypy failure count from 134 -> 15.

Agent transcript: https://claudescope.sentry.dev/share/mi26dmBkpSB5zU45vLb9vayuq61XpEbOEAaKoC-2AGQ
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 20, 2026
Fixes the 15 remaining mypy 1.20 test failures so the full-repo run is clean.

Patterns fixed:
- Replace `x.refresh_from_db()` with a fresh `Model.objects.get(id=x.id)`
  assignment in tests where mypy retained narrowing from an earlier assertion
  (e.g. `assert widget.discover_widget_split is None`). refresh_from_db mutates
  in place so mypy never re-widens; an assignment does.
- Guard or cast `Mapping | None` / `object` before `**kwargs` splats.
- Assert `is not None` before dereferencing an Optional parsed MRI.
- Type a heterogeneous debug_meta case list as `list[dict[str, Any]]`.
- Annotate exchange_token test result as `dict[str, Any]` — the declared
  return type is `dict[str, str]` but real OAuth responses include ints.
- Compare notification_context.integration_id against an int, not a str.

Agent transcript: https://claudescope.sentry.dev/share/_Bezr4OWYESAQM3P9KhWPgffIOzp6lSEgTG_mq5brNM
JoshFerge added a commit that referenced this pull request Apr 20, 2026
Both `RegressionDetector` and `AttributeHandler` declared their configuration
fields as dataclass instance attributes (via `@dataclass(frozen=True)`), but
every usage accesses them through the class (`cls.source`, `cls.minimum_path_length`).
The classes are never instantiated; subclasses override the fields as class-
level attributes.

Convert the fields to `ClassVar[T]` so access through the class is valid and
drop the no-op `@dataclass(frozen=True)` decorators.

Prep work for the mypy 1.20 upgrade (#113419), which adds a new `misc` error
for 'Cannot access instance-only attribute on class object'.

Agent transcript: https://claudescope.sentry.dev/share/JZ-p3R-cM7eIdQz7AaZNFl38wjaYVyV7YpBDM4yLTyU
JoshFerge added a commit that referenced this pull request Apr 20, 2026
`GroupType` is never instantiated in production: subclasses declare their
configuration as class-level attributes (`type_id = 1001`, `slug = "foo"`,
etc.) and the registry stores the classes themselves. Despite that, the base
declared fields as `@dataclass(frozen=True)` instance attributes, so every
access like `group_type.type_id` (where `group_type: type[GroupType]`) is
really class-level access.

Convert the fields to `ClassVar[T]`, preserving the same defaults. Also
convert the `ReplayGroupTypeDefaults` mixin's `notification_config` for the
same reason.

Behavior change: `GroupType.__post_init__` was previously dead code (nothing
instantiates `GroupType`), so category validation never actually ran. Move
the same validation to `__init_subclass__` so it fires at subclass-definition
time. Update the two tests that were constructing `GroupType(...)` (not a real
production usage pattern) to define subclasses and the category-validation
test to expect the failure at class-definition time.

Prep work for the mypy 1.20 upgrade (#113419) — safe under 1.19.1.

Agent transcript: https://claudescope.sentry.dev/share/8kuOPo_F7g0JelnKiHguToNZr0_y4AKNCOGNvydSZac
JoshFerge added a commit that referenced this pull request Apr 20, 2026
`sentry.models.group.GroupStatus` is a plain class whose members are ints
(`RESOLVED = 1`, `IGNORED = 2`, etc.), not an enum. Callers of these
functions all pass ints, and the in-function `==` comparisons against
`GroupStatus.RESOLVED` are int-vs-int. But the parameters were annotated as
`GroupStatus`, i.e. 'instance of GroupStatus'.

Under `strict_equality = true` the comparison becomes semantically
unreachable (instance-of-class never equals int), which is surfaced as
`[unreachable]` errors by stricter mypy. Change the annotations to `int`
to match how the values are actually used:

- `fetch_alert_threshold`
- `fetch_resolve_threshold`
- `AlertContext.from_workflow_engine_models`
- `MetricAlertNotificationMessageBuilder.build_alert_context`

No runtime behavior change. Prep for the mypy 1.20 upgrade (#113419).

Agent transcript: https://claudescope.sentry.dev/share/zuptd8j6fTczb1hxTiv3VRqXHCYcX_7vZGRag0vi_DY
JoshFerge added a commit that referenced this pull request Apr 20, 2026
Three `cast(...)` calls that mypy 1.20.1 reports as redundant, and which
are in fact redundant under 1.19.1 too (mypy already infers the narrowed
type from the surrounding `if unit in constants.SIZE_UNITS` etc. checks).

- `src/sentry/search/eap/columns.py`: drop `cast(constants.SearchType, ...)`
  inside a branch already guarded by membership in DURATION_TYPE/SIZE_TYPE.
- `src/sentry/search/events/builder/base.py`: drop `cast(constants.SizeUnit, unit)`
  and `cast(constants.DurationUnit, unit)` inside the corresponding membership-
  checked branches.
- `src/sentry/search/eap/trace_metrics/config.py`: drop
  `cast(TraceMetricType, metric_type)` where `metric_type` is already
  narrowed by `if ... not in ALLOWED_METRIC_TYPES` early-return.

Prep for the mypy 1.20 upgrade (#113419).

Agent transcript: https://claudescope.sentry.dev/share/rGGex5V3dtTetZqF-KULYaNyoOlBBLtcZWOK-0xI95U
@github-actions

github-actions Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on 1b18fd5 in this run:

tests/sentry/incidents/test_logic.py::UpdateAlertRuleTriggerAction::test_pagerdutylog
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/incidents/test_logic.py:2978: in test_pagerduty
    assert action.target_identifier == str(target_identifier)
E   AssertionError: assert 41 == '41'
E    +  where 41 = <AlertRuleTriggerAction at 0x7f0352adf3e0: id=12>.target_identifier
E    +  and   '41' = str(41)
tests/sentry/workflow_engine/endpoints/test_validators.py::TestBaseGroupTypeDetectorValidator::test_validate_type_validlog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/workflow_engine/endpoints/test_validators.py:118: in test_validate_type_valid
    class TestGroupType(GroupType):
src/sentry/issues/grouptype.py:282: in __init_subclass__
    registry.add(cls)
src/sentry/issues/grouptype.py:117: in add
    raise ValueError(
E   ValueError: A group type with the type_id 1 has already been registered.
tests/sentry/workflow_engine/endpoints/test_validators.py::TestBaseGroupTypeDetectorValidator::test_validate_type_incompatiblelog
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/workflow_engine/endpoints/test_validators.py:142: in test_validate_type_incompatible
    class TestGroupType(GroupType):
src/sentry/issues/grouptype.py:282: in __init_subclass__
    registry.add(cls)
src/sentry/issues/grouptype.py:117: in add
    raise ValueError(
E   ValueError: A group type with the type_id 1 has already been registered.
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py::TestBaseMetricAlertHandler::test_build_notification_contextlog
[gw0] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py:375: in test_build_notification_context
    assert notification_context.integration_id == 1234567890
E   AssertionError: assert '1234567890' == 1234567890
E    +  where '1234567890' = NotificationContext(id=33, integration_id='1234567890', target_identifier='channel456', target_display=None, target_type=None, sentry_app_config=None, sentry_app_id=None).integration_id

JoshFerge added a commit that referenced this pull request Apr 20, 2026
…arrowing

Tests like:

    assert widget.discover_widget_split is None   # narrows to None
    ...
    widget.refresh_from_db()                      # mypy keeps the narrowing
    assert widget.discover_widget_split == TRANSACTION_LIKE  # mypy: unreachable

`refresh_from_db()` mutates the object in place, so mypy does not reset the
narrowed attribute type — later assertions comparing against non-None values
become semantically unreachable under stricter checkers. Replace with
`x = Model.objects.get(id=x.id)`, which is semantically equivalent (fresh
row from the same table) and an assignment resets the inferred type.

Applied in:

- tests/sentry/models/test_dashboard.py
- tests/snuba/api/endpoints/test_organization_events_mep.py
- tests/snuba/api/endpoints/test_organization_events_stats_mep.py
- tests/sentry/monitors/logic/test_mark_ok.py
- tests/sentry/grouping/seer_similarity/test_training_mode.py

Prep for the mypy 1.20 upgrade (#113419). Safe under 1.19.1.

Agent transcript: https://claudescope.sentry.dev/share/hYewe-LTcVPdbrD9iGU6eeyfLBiHv5fKzkiUjiPAepc
JoshFerge added a commit that referenced this pull request Apr 20, 2026
Small one-off type hint corrections in tests. Each is behavior-neutral.

- test_naming_layer.py: `assert parsed_mri is not None` before
  dereferencing `.mri_string`.
- test_provider.py: annotate the `exchange_token` test result as
  `dict[str, Any]`. The declared return type is `dict[str, str]` but
  real OAuth responses include ints (`expires_in`); this is a
  preexisting lie in the production signature, so the test locally
  widens until that gets fixed separately.
- test_occurrence_consumer.py: annotate a heterogeneous debug_meta case
  list as `list[dict[str, Any]]`.
- test_sentry_apps.py: guard `Mapping | None` before `**data`.
- test_metric_alert_registry_handlers.py: compare
  `notification_context.integration_id` against an int (the dataclass
  field type) rather than a str.
- test_logic.py: compare `target_identifier` against
  `str(target_identifier)` since the model field is typed `str`.

Prep for the mypy 1.20 upgrade (#113419). Safe under 1.19.1.

Agent transcript: https://claudescope.sentry.dev/share/zQXk8MwFd_O336VWRbM_DtJHLs12UetlIk6Q3HiZFeY
JoshFerge added a commit that referenced this pull request Apr 22, 2026
\`sentry.models.group.GroupStatus\` is a plain class whose members are
ints (\`RESOLVED = 1\`, \`IGNORED = 2\`, etc.) — not an enum. Callers of
the functions below all pass ints, and the in-function \`==\`
comparisons (\`group_status == GroupStatus.RESOLVED\`) are int-vs-int.
But the parameters were annotated as \`GroupStatus\`, i.e. \"instance of
GroupStatus\", which is never what the callers pass.

Under \`strict_equality = true\` the comparisons become semantically
unreachable (instance-of-class never equals int). Stricter mypy reports
them as \`[unreachable]\`.

Change the annotations to \`int\` to match actual usage:

- \`fetch_alert_threshold\`
- \`fetch_resolve_threshold\`
- \`AlertContext.from_workflow_engine_models\`
- \`MetricAlertNotificationMessageBuilder.build_alert_context\`

No runtime behavior change. Prep for the mypy 1.20 upgrade (#113419).
Safe under 1.19.1.


Agent transcript:
https://claudescope.sentry.dev/share/wKKwnZeeYc-V3zQbolQDCON52n93vyqkCmPrIs_kbnI
JoshFerge added a commit that referenced this pull request Apr 23, 2026
…arrowing (#113427)

Tests like:

\`\`\`python
assert widget.discover_widget_split is None   # narrows to None
...
widget.refresh_from_db()                      # mypy keeps the narrowing
assert widget.discover_widget_split == TRANSACTION_LIKE # mypy:
unreachable
\`\`\`

\`refresh_from_db()\` mutates the object in place, so mypy doesn't reset
the narrowed attribute type — subsequent assertions comparing against
non-None values become semantically unreachable under stricter checkers.
Replace with \`x = Model.objects.get(id=x.id)\`, which is semantically
equivalent (fresh row from the same table) and an assignment resets the
inferred type.

Applied in:

- \`tests/sentry/models/test_dashboard.py\`
- \`tests/snuba/api/endpoints/test_organization_events_mep.py\`
- \`tests/snuba/api/endpoints/test_organization_events_stats_mep.py\`
- \`tests/sentry/monitors/logic/test_mark_ok.py\`
- \`tests/sentry/grouping/seer_similarity/test_training_mode.py\`

### Why this PR exists

Prep for the mypy upgrade to 1.20.1 in #113419. Safe under the current
mypy (1.19.1). Misc other test-side typing nits live separately in the
companion PR.
JoshFerge added a commit that referenced this pull request Apr 24, 2026
…ClassVar (#113422)

Both `RegressionDetector`
(`src/sentry/statistical_detectors/detector.py`) and `AttributeHandler`
(`src/sentry/rules/conditions/event_attribute.py`) declared their
configuration fields as dataclass instance attributes via
`@dataclass(frozen=True)`, but every usage accesses them through the
class (`cls.source`, `cls.minimum_path_length`, etc.). The classes are
never instantiated; subclasses override the fields as class-level
attributes (`source = "transaction"`, `minimum_path_length = 1`).

Convert the fields to `ClassVar[T]` and drop the no-op
`@dataclass(frozen=True)` decorators. No runtime behavior change.

### Why this PR exists

Prep for the mypy upgrade to 1.20.1 in #113419. 1.20.1 adds a new
`[misc]` check, "Cannot access instance-only attribute on class object,"
which surfaces this pattern. Splitting the fix out so each targeted
reviewer only has to look at their own area.

This PR is safe under the current mypy (1.19.1).


Agent transcript:
https://claudescope.sentry.dev/share/8Gzqw1K3cHTGBqYv-FAytvqDyA86B3vsiZyoJkHL7DM
JoshFerge added a commit that referenced this pull request Apr 24, 2026
Small one-off type hint corrections in tests, each behavior-neutral.
Split off from the `refresh_from_db()` refactor in #113427 so the
patterns can be reviewed separately.

- `test_naming_layer.py`: `assert parsed_mri is not None` before
dereferencing `.mri_string`.
- `test_provider.py`: annotate the `exchange_token` test result as
`dict[str, Any]`. The declared return type is `dict[str, str]`, but real
OAuth responses include ints (`expires_in`) — this is a preexisting lie
in the production signature, so the test locally widens until that gets
fixed separately.
- `test_occurrence_consumer.py`: annotate a heterogeneous debug_meta
case list as `list[dict[str, Any]]`.
- `test_sentry_apps.py`: guard `Mapping | None` before `**data`.
- `test_metric_alert_registry_handlers.py`: pass `integration_id` as an
int in the fixture so the in-memory dataclass value matches the declared
`int | None` type (no DB round-trip coerces it).
- `test_logic.py`: stringify both sides of the `target_identifier`
assertion in the update path. `update_alert_rule_trigger_action` leaves
`target.identifier` as int in memory (unlike the create path, which
wraps with `str()`), so stringifying avoids the runtime mismatch while
keeping mypy happy.

### Why this PR exists

Prep for the mypy upgrade to 1.20.1 in #113419. Safe under the current
mypy (1.19.1).


Agent transcript:
https://claudescope.sentry.dev/share/OOKfaLYBcSwWWD48Y6-ebfs_iQCylldqs4WhtB_1ibU
JoshFerge added a commit that referenced this pull request Apr 24, 2026
`GroupType` is never instantiated in production — subclasses declare
their configuration as class-level attributes (`type_id = 1001`, `slug =
"foo"`, etc.) and the registry stores the classes themselves. Despite
that, the base declared fields as `@dataclass(frozen=True)` instance
attributes, so every access like `group_type.type_id` (where
`group_type: type[GroupType]`) was really class-level access against an
instance-level annotation.

Convert the fields to `ClassVar[T]`, preserving the same defaults. Also
convert `ReplayGroupTypeDefaults.notification_config` for the same
reason.

### Small behavior change

`GroupType.__post_init__` was previously dead code — nothing
instantiates `GroupType`, so the category-value validation never
actually ran. Move the same validation to `__init_subclass__` so it
fires at subclass-definition time (earlier, and actually reachable).
Updates:

- `test_grouptype.py::test_category_validation` — now expects the
`ValueError` at class-definition time.
- `test_validators.py` — two tests were instantiating `GroupType(...)`
to build a mock; since the base no longer takes fields as constructor
args, convert them to subclasses of `GroupType` instead (which matches
real production usage).

### Why this PR exists

Prep for the mypy upgrade to 1.20.1 in #113419. 1.20.1 adds a new
`[misc]` check, "Cannot access instance-only attribute on class object,"
and `GroupType` is the single biggest cluster of such errors in the
repo. Splitting it out so the targeted reviewers only have to look at
their own areas.

Safe under the current mypy (1.19.1).


Agent transcript:
https://claudescope.sentry.dev/share/JFAQdL9BKvw8zOc8RROKUSNl-Xpuu8y4p4URoIp7DDk
…de-mypy-to-1-20-1

# Conflicts:
#	tests/sentry/incidents/test_logic.py
#	tests/sentry/models/test_dashboard.py

Agent transcript: https://claudescope.sentry.dev/share/D--sRHsVvSPk6WPQmSZcYG-A3qGMCOHGYki10ltOJDI
Three new mypy 1.20 failures surfaced from master after the merge:

- bootstrap-snuba.py:214 — fail() always calls sys.exit(1), so annotate
  it as NoReturn. Fixes the "int(workers_str)" call on a str|None arg.
- columns.py:498 — cast trace_metric.metric_unit to SearchType; mypy
  doesn't narrow from `x in set[SearchType]` membership.
- test_logic.py::test_alert_rule_owner — refetch via AlertRule.objects
  .get(id=...) between update_alert_rule calls so mypy drops the narrowed
  (user_id, team_id) types. Same pattern as #113427.

Agent transcript: https://claudescope.sentry.dev/share/n_liZXmbQ0rj2hiJIxs4xsZr1MegSMvDxXqAl75y_F8
mypy 1.20.1 narrows `trace_metric.metric_unit` via the `in DURATION_TYPE`
/ `in SIZE_TYPE` set-membership checks, so the cast I added earlier was
redundant and tripped `warn_redundant_casts`.

(Locally I was still on 1.20.0 which lacked that narrowing, which is why
I missed it before pushing.)

Agent transcript: https://claudescope.sentry.dev/share/qVN5T3yPojgSEpPxyZeF1DC78Y1TPOBuaCbCjqQuHps
The mypy 1.20.0 false positives I worked around don't exist under
1.20.1 (which is what CI actually runs). Drop the test_logic.py
queryset refetches and the bootstrap-snuba.py NoReturn annotation;
full-repo mypy passes cleanly under 1.20.1 without them.

Agent transcript: https://claudescope.sentry.dev/share/WDLHqJ2mEu0M75cxgnMiWXrgXC6nT52jGIlB3VRCRR8
@JoshFerge
JoshFerge marked this pull request as ready for review April 24, 2026 16:13
@JoshFerge
JoshFerge requested review from a team as code owners April 24, 2026 16:13
@JoshFerge
JoshFerge requested a review from a team April 24, 2026 16:13
return constants.SIZE_UNITS[cast(constants.SizeUnit, unit)] * value # type: ignore[redundant-cast]
elif unit in constants.DURATION_UNITS:
return constants.DURATION_UNITS[cast(constants.DurationUnit, unit)] * value
return constants.DURATION_UNITS[cast(constants.DurationUnit, unit)] * value # type: ignore[redundant-cast]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If its redundant can the cast be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, will do so in follow up 👍🏼 just caught in a chicken and egg as roughly 1 incompatible change with the new upgrade lands every day, so ignoring in this PR and will land fixes after the mypy upgrade PR is merged.

or trace_metric.metric_unit in constants.SIZE_TYPE
):
resolved_search_type = cast(constants.SearchType, trace_metric.metric_unit)
resolved_search_type = cast( # type: ignore[redundant-cast]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the cast be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do so in follow up 👍🏼

return TraceMetric(
metric_name=metric_name,
metric_type=cast(TraceMetricType, metric_type),
metric_type=cast(TraceMetricType, metric_type), # type: ignore[redundant-cast]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove cast?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do so in follow up 👍🏼

@JoshFerge
JoshFerge merged commit e4fbee6 into master Apr 24, 2026
80 checks passed
@JoshFerge
JoshFerge deleted the joshferge/ref/upgrade-mypy-to-1-20-1 branch April 24, 2026 16:18
JoshFerge added a commit that referenced this pull request Apr 24, 2026
mypy 1.20.1 now flags passing `auth.organization_id` (typed `int | None`)
to `OrganizationGlobalAccess` (expects `int`). Narrow the value locally
before the call instead of carrying a `# type: ignore[arg-type]`.

Follow-up to #113419 — removes one of the targeted ignores that PR
introduced.

Agent transcript: https://claudescope.sentry.dev/share/WG-0likblPhNpRq3ev8pLoZRMrn8oSFOE2xrVHQm5ds
JoshFerge added a commit that referenced this pull request Apr 24, 2026
`PyMemcacheCache._options` is typed `dict | None`; splatting None into
`**kwargs` is a runtime TypeError. Fall back to `{}` so the arg-type
ignore introduced in #113419 can be removed.

Agent transcript: https://claudescope.sentry.dev/share/asYXfLRHOo-uGu5pLDRYXImp8ccvxh-gX3E_3dVUDHU
JoshFerge added a commit that referenced this pull request Apr 24, 2026
The arg-type ignore was added in #113419; document the underlying
mismatch (team_roles can contain (team, None) tuples when
organizations:team-roles is disabled, which doesn't match the declared
signature) so the follow-up either fixes the signature or the caller.

Agent transcript: https://claudescope.sentry.dev/share/c6N6Q15yfk5b4v9xtEM2JZaFwXItVVVaA_yuZo2UyDY
JoshFerge added a commit that referenced this pull request Apr 24, 2026
mypy 1.20.1 narrows `trace_metric.metric_unit` via the
`in DURATION_TYPE / SIZE_TYPE` membership checks, so the
`cast(constants.SearchType, ...)` is redundant under the new pin.
Remove it along with the `# type: ignore[redundant-cast]` #113419
parked there.

Agent transcript: https://claudescope.sentry.dev/share/IQw7RcSfBRYsfH4fqUWuAB3LmwTb1eK5eIUHbhG9Z74
JoshFerge added a commit that referenced this pull request Apr 24, 2026
mypy 1.20.1 narrows `metric_type` to the `TraceMetricType` Literal via
the preceding `if metric_type not in (...)` check, so the cast is
redundant under the new pin. Drop it and the unused `cast` import, and
remove the `# type: ignore[redundant-cast]` #113419 added.

Agent transcript: https://claudescope.sentry.dev/share/73VcpxsrWayhrckFm4nt6rNv1Ut6V2OD-g2j5UkaJxM
JoshFerge added a commit that referenced this pull request Apr 24, 2026
mypy 1.20.1 narrows `unit` via the `in SIZE_UNITS` / `in DURATION_UNITS`
membership checks, making the `cast(SizeUnit/DurationUnit, unit)` calls
redundant. Drop both along with the `# type: ignore[redundant-cast]`
#113419 parked on each line.

Agent transcript: https://claudescope.sentry.dev/share/D5BcySnDeVsi_TvpdsbF4DnHgDCKeoLRjrK-4DBQaMA
JoshFerge added a commit that referenced this pull request Apr 24, 2026
## Summary

Drop the two \`cast(...)\` calls in
\`BaseQueryBuilder.resolve_measurement_value\` — mypy 1.20.1 narrows
\`unit\` via \`in SIZE_UNITS / DURATION_UNITS\` membership, so both
casts are redundant under the new pin. Removes the pair of \`# type:
ignore[redundant-cast]\` comments #113419 parked on these lines.

Drafted because it depends on #113419.

## Test plan

- [ ] \`.venv/bin/python -m mypy
src/sentry/search/events/builder/base.py\` passes


Agent transcript:
https://claudescope.sentry.dev/share/9knBZJ8vsizIvYD0SEHZTCEVeYi3SKsV51XS1gS1L0k
JoshFerge added a commit that referenced this pull request Apr 24, 2026
## Summary

Drop the \`cast(TraceMetricType, metric_type)\` in
\`get_trace_metric_from_request\` — mypy 1.20.1 narrows \`metric_type\`
via the preceding validation check, so the cast is redundant under the
new pin. Removes the \`# type: ignore[redundant-cast]\` #113419 parked
there.

Drafted because it depends on #113419.

## Test plan

- [ ] \`.venv/bin/python -m mypy
src/sentry/search/eap/trace_metrics/config.py\` passes


Agent transcript:
https://claudescope.sentry.dev/share/EAwMhN54lGJy_R4gjE03VMzhxtMKTejQyHgo_pGSXt4
JoshFerge added a commit that referenced this pull request Apr 24, 2026
## Summary

Drop the \`cast(constants.SearchType, trace_metric.metric_unit)\` in
\`TraceMetricAggregateDefinition\` — mypy 1.20.1 narrows via the \`x in
DURATION_TYPE / SIZE_TYPE\` membership checks, so the cast is redundant
under the new pin. Removes the \`# type: ignore[redundant-cast]\` that
#113419 parked there.

Drafted because it depends on #113419.

## Test plan

- [ ] \`.venv/bin/python -m mypy src/sentry/search/eap/columns.py\`
passes


Agent transcript:
https://claudescope.sentry.dev/share/s6xsPeER6hqruuVvkujoI7fjuxD2y1wtbo-39lZR6yk
JoshFerge added a commit that referenced this pull request Apr 27, 2026
## Summary

Remove the \`# type: ignore[arg-type]\` on \`auth.organization_id\` in
\`from_auth\` by narrowing the value to \`int\` before passing it to
\`OrganizationGlobalAccess\`.

Follow-up to #113419. 
## Test plan

- [ ] \`.venv/bin/python -m mypy src/sentry/auth/access.py\` passes
- [ ] Existing \`from_auth\` tests still pass


Agent transcript:
https://claudescope.sentry.dev/share/l4qdLaYXiQY9XtMd5ykax-e5mzkLHpsYfnHY4Jjeaoo
JoshFerge added a commit that referenced this pull request Apr 28, 2026
## Summary

\`PyMemcacheCache._options\` is typed \`dict | None\` but
\`**self._options\` would explode at runtime on \`None\`. Fall back to
\`{}\`, which also lets us drop the \`# type: ignore[arg-type]\` that
#113419 added.

Agent transcript:
https://claudescope.sentry.dev/share/ZoHjMlN-lDWKU2242qjXGR-0l_UDipLzt6dZKGatk3Q
cleptric pushed a commit that referenced this pull request May 5, 2026
## Summary

Remove the \`# type: ignore[arg-type]\` on \`auth.organization_id\` in
\`from_auth\` by narrowing the value to \`int\` before passing it to
\`OrganizationGlobalAccess\`.

Follow-up to #113419. 
## Test plan

- [ ] \`.venv/bin/python -m mypy src/sentry/auth/access.py\` passes
- [ ] Existing \`from_auth\` tests still pass


Agent transcript:
https://claudescope.sentry.dev/share/l4qdLaYXiQY9XtMd5ykax-e5mzkLHpsYfnHY4Jjeaoo
cleptric pushed a commit that referenced this pull request May 5, 2026
## Summary

\`PyMemcacheCache._options\` is typed \`dict | None\` but
\`**self._options\` would explode at runtime on \`None\`. Fall back to
\`{}\`, which also lets us drop the \`# type: ignore[arg-type]\` that
#113419 added.

Agent transcript:
https://claudescope.sentry.dev/share/ZoHjMlN-lDWKU2242qjXGR-0l_UDipLzt6dZKGatk3Q
@github-actions github-actions Bot locked and limited conversation to collaborators May 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants