Repository navigation
ref(typing): Remove casts mypy does not need - #132050
Merged
Merged
Conversation
Every remaining typing.cast was removed and mypy was rerun, putting a cast back wherever its removal produced an error, until the strict run was clean. The 292 casts this leaves out did not change what mypy accepts. A cast does nothing at runtime, so behavior is unchanged. Imports used only by those casts are dropped. Co-authored-by: Armen Zambrano G. <armenzg@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Leftover no-op self-assignments
- Removed the dead self-assignments
queries = queriesandproject_id = project_idleft behind after stripping typing.cast.
- Removed the dead self-assignments
Or push these changes by commenting:
@cursor push 1ca3f386d6
Preview (1ca3f386d6)
diff --git a/src/sentry/api/serializers/rest_framework/dashboard.py b/src/sentry/api/serializers/rest_framework/dashboard.py
--- a/src/sentry/api/serializers/rest_framework/dashboard.py
+++ b/src/sentry/api/serializers/rest_framework/dashboard.py
@@ -1159,7 +1159,6 @@ def validate_query_transformation_updates(self, widgets: list[dict[str, Any]]) -
widget_errors: list[dict[str, Any]] = [{} for _ in widgets]
for widget_index, widget in enumerate(widgets):
queries = widget.get("queries", [])
- queries = queries
query_errors: list[dict[str, Any] | list[Any]] = [{} for _ in queries]
for query_index, data in enumerate(queries):
if "aggregates" not in data and "transformations" not in data:
@@ -1159,7 +1159,6 @@ def validate_query_transformation_updates(self, widgets: list[dict[str, Any]]) -
widget_errors: list[dict[str, Any]] = [{} for _ in widgets]
for widget_index, widget in enumerate(widgets):
queries = widget.get("queries", [])
- queries = queries
query_errors: list[dict[str, Any] | list[Any]] = [{} for _ in queries]
for query_index, data in enumerate(queries):
if "aggregates" not in data and "transformations" not in data:
diff --git a/src/sentry/search/events/datasets/function_aliases.py b/src/sentry/search/events/datasets/function_aliases.py
--- a/src/sentry/search/events/datasets/function_aliases.py
+++ b/src/sentry/search/events/datasets/function_aliases.py
@@ -59,7 +59,6 @@ def resolve_project_threshold_config(
project_threshold_config_keys = []
project_threshold_config_values = []
for project_id, metric in project_threshold_configs:
- project_id = project_id
metric = TRANSACTION_METRICS[cast(int, metric)]
if metric == constants.DEFAULT_PROJECT_THRESHOLD_METRIC:
# small optimization, if the configuration is equal to the default,
@@ -59,7 +59,6 @@ def resolve_project_threshold_config(
project_threshold_config_keys = []
project_threshold_config_values = []
for project_id, metric in project_threshold_configs:
- project_id = project_id
metric = TRANSACTION_METRICS[cast(int, metric)]
if metric == constants.DEFAULT_PROJECT_THRESHOLD_METRIC:
# small optimization, if the configuration is equal to the default,You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 12ca8df. Configure here.
Removing cast() from x = cast(T, x) left a no-op x = x in two places. Co-authored-by: Armen Zambrano G. <armenzg@users.noreply.github.com>
armenzg
requested review from
alwx and
antonis
and removed request for
a team
November 20, 2026 19:58
wedamija
approved these changes
Nov 20, 2026
joshuarli
approved these changes
Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Removes 292 of the repository's 1,607
typing.castcalls (178 files, Python only).strict = truealready reports exactly-redundant casts, so every cast here narrowed or widened a type, but mypy accepts the code without them. To find them, everytyping.castoutsidebin/was removed, mypy was run, and the cast nearest each error was put back, repeating until the strict run passed. Imports used only by the removed casts were dropped.A cast does nothing at runtime, so this changes no behavior. The casts that remain are needed by mypy. Most narrow
Any, JSON, or a wider declared type. Replacing those with real types or runtime checks would change behavior or need declaration changes upstream, so that is left for focused follow-ups.tools/migrations/drop_pending_deletions.pyandsrc/sentry/integrations/gitlab/utils.pyare left out because #132048 changes them.Test plan
mypyon the whole repository:Success: no issues found in 8858 source files.mypyagainst this branch reports no new errors. The only failures are inbin/deployscripts that import ascriptspackage this machine does not have.prek run --fileson every changed file.srcmodules and 43 changed test modules with Django configured.Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.