Skip to content

test(typing): Misc test-side type hint fixes#113428

Merged
JoshFerge merged 2 commits into
masterfrom
joshferge/test/misc-typing-nits
Apr 24, 2026
Merged

test(typing): Misc test-side type hint fixes#113428
JoshFerge merged 2 commits into
masterfrom
joshferge/test/misc-typing-nits

Conversation

@JoshFerge

@JoshFerge JoshFerge commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

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

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
Align test assertions with runtime values while keeping mypy 1.20 happy.

- test_metric_alert_registry_handlers.py: pass integration_id as 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 asserting equality directly works, but mypy 1.20
  flags str-vs-int equality as unreachable.

Agent transcript: https://claudescope.sentry.dev/share/QGDOrXCYdnepcRCKEWfP2tfURgdqeR__SG95UkYZUws
@getsentry getsentry deleted a comment from github-actions Bot Apr 24, 2026
@JoshFerge
JoshFerge marked this pull request as ready for review April 24, 2026 14:30
@JoshFerge
JoshFerge requested review from a team as code owners April 24, 2026 14:30
@JoshFerge
JoshFerge requested a review from a team April 24, 2026 14:30

@shellmayr shellmayr left a comment

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.

LGTM!

@JoshFerge
JoshFerge merged commit 9e38525 into master Apr 24, 2026
51 checks passed
@JoshFerge
JoshFerge deleted the joshferge/test/misc-typing-nits branch April 24, 2026 14:34
JoshFerge added a commit that referenced this pull request Apr 24, 2026
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)

- #113422 — `ref(typing)`: `RegressionDetector` + `AttributeHandler` →
`ClassVar`
- #113423 — `ref(issues)`: `GroupType` → `ClassVar` + move validation to
`__init_subclass__`
- #113424 — `fix(typing)`: `group_status` args are `int`, not
`GroupStatus`
- #113427 — `test(typing)`: refetch via queryset instead of
`refresh_from_db` after narrowing
- #113428 — `test(typing)`: misc test-side type hint fixes

### What's in this PR

- Bump `mypy>=1.19.1` → `mypy>=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.

- #113927 — `fix(typing)`: narrow `organization_id` in `from_auth`
- #113928 — `fix(typing)`: guard None options in `ReconnectingMemcache`
- #113929 — `docs(typing)`: annotate the `save_team_assignments` ignore
with a FIXME
- #113930 — `ref(typing)`: drop redundant cast in trace metric search
type
- #113932 — `ref(typing)`: drop redundant cast on
`TraceMetric.metric_type`
- #113933 — `ref(typing)`: drop redundant casts in
`resolve_measurement_value`

### 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)
@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants