Skip to content

ref: Drop redundant casts in search builders#113426

Closed
JoshFerge wants to merge 1 commit into
masterfrom
joshferge/ref/drop-redundant-casts-search
Closed

ref: Drop redundant casts in search builders#113426
JoshFerge wants to merge 1 commit into
masterfrom
joshferge/ref/drop-redundant-casts-search

Conversation

@JoshFerge

@JoshFerge JoshFerge commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Three `cast(...)` calls that mypy already infers correctly — they fire `[redundant-cast]` under mypy 1.20.1 and are genuinely redundant under 1.19.1 too. Each is inside a branch already guarded by a membership check or early-return that narrows the value.

  • `src/sentry/search/eap/columns.py`: `cast(constants.SearchType, trace_metric.metric_unit)` — inside `if ... in DURATION_TYPE or ... in SIZE_TYPE`.
  • `src/sentry/search/events/builder/base.py`: `cast(constants.SizeUnit, unit)` / `cast(constants.DurationUnit, unit)` — inside `if unit in constants.SIZE_UNITS` / `DURATION_UNITS`.
  • `src/sentry/search/eap/trace_metrics/config.py`: `cast(TraceMetricType, metric_type)` — already narrowed by the `if metric_type not in ALLOWED_METRIC_TYPES: return None` guard above.

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

Agent transcript: https://claudescope.sentry.dev/share/lVivF9WN2X9tBvTh2KH4Va299tH3t04bTyP0awki7SU

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 added the Scope: Backend Automatically applied to PRs that change backend components label Apr 20, 2026
@JoshFerge

Copy link
Copy Markdown
Contributor Author

Superseded by #113419, which already contains these exact cast drops. Closing as duplicate.

@JoshFerge JoshFerge closed this Apr 23, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators May 9, 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.

1 participant