Skip to content

Lots of "var-annotated" after upgrading to mypy 1.18.1 #19856

@asottile-sentry

Description

@asottile-sentry

Bug Report

I have not narrowed down a minimal reproduction but I have bisected

unfortunately the codebase is fairly large and I can't seem to make a reproduction without involving django-stubs in some way 🤔

I bisected using this shell script:

set -euxo pipefail

cd ../sentry

.venv/bin/pip uninstall -yqq mypy

.venv/bin/pip install -qq ../mypy

(.venv/bin/mypy src/sentry/sentry_apps/models/platformexternalissue.py || true) > log

! grep 'Need type annotation for "annotations_by_group_id"' log

which bisected to:

...

a8d2f1334b48dfbee5fe04d6bd1f0b145a13d9d9 is the first bad commit
commit a8d2f1334b48dfbee5fe04d6bd1f0b145a13d9d9
Author: Ivan Levkivskyi <[email protected]>
Date:   Sun Jul 27 22:49:16 2025 +0100

    Cache type_object_type() (#19514)
    
    This gives almost 4% performance boost (Python 3.12, compiled). Note
    there is an old bug in `type_object_type()`, we treat not ready types as
    `Any` without deferring, I disable caching in this case.
    
    Unfortunately, using this in fine-grained mode is tricky, essentially I
    have three options:
    * Use some horrible hacks to invalidate cache when needed
    * Add (expensive) class target dependency from `__init__`/`__new__`
    * Only allow constructor caching during initial load, but disable it in
    fine-grained increments
    
    I decided to choose the last option. I think it has the best balance
    complexity/benefits.

 mypy/checker.py        |  7 ++++++-
 mypy/checker_shared.py |  1 +
 mypy/nodes.py          |  6 ++++++
 mypy/semanal_infer.py  |  3 +++
 mypy/server/update.py  |  6 ++++--
 mypy/typeops.py        | 40 +++++++++++++++++++++++++++++++++++-----
 6 files changed, 55 insertions(+), 8 deletions(-)
bisect found first bad commit

a8d2f13 / #19514

To Reproduce

https://github.com/getsentry/sentry :'( yeah I know it's big -- here's one specific case:

src/sentry/sentry_apps/models/platformexternalissue.py:36: error: Need type annotation for "annotations_by_group_id"  [var-annotated]

https://github.com/getsentry/sentry/blob/4850817486f31a460ecfd49f8f1b5373102e0b29/src/sentry/sentry_apps/models/platformexternalissue.py#L36

here's a few more examples
src/sentry/sentry_apps/models/platformexternalissue.py:36: error: Need type annotation for "annotations_by_group_id"  [var-annotated]
src/sentry/seer/similarity/types.py:61: error: Need type annotation for "optional_incoming_keys" (hint: "optional_incoming_keys: dict[<type>, <type>] = ...")  [var-annotated]
src/sentry/api/serializers/models/organization_member/utils.py:28: error: Need type annotation for "result_teams"  [var-annotated]
src/sentry/api/serializers/models/organization_member/utils.py:29: error: Need type annotation for "result_teams_with_roles"  [var-annotated]
src/sentry/models/group.py:350: error: Need type annotation for "project_short_id_lookup"  [var-annotated]
src/sentry/models/groupowner.py:254: error: Need type annotation for "owner_details"  [var-annotated]
src/sentry/search/utils.py:605: error: Need type annotation for "result"  [var-annotated]
src/sentry/search/utils.py:606: error: Need type annotation for "query_params"  [var-annotated]
src/sentry/dynamic_sampling/tasks/boost_low_volume_projects.py:306: error: Need type annotation for "aggregated_projects"  [var-annotated]
src/sentry/issues/ignored.py:71: error: Need type annotation for "groups_by_project_id"  [var-annotated]
src/sentry/issues/status_change.py:128: error: Need type annotation for "groups_by_project_id"  [var-annotated]
src/sentry/snuba/rpc_dataset_common.py:671: error: Need type annotation for "map_result_key_to_timeseries"  [var-annotated]
src/sentry/snuba/trace.py:309: error: Need type annotation for "occurrence_ids"  [var-annotated]
src/sentry/snuba/trace.py:310: error: Need type annotation for "occurrence_issue_ids"  [var-annotated]
src/sentry/snuba/trace.py:533: error: Need type annotation for "id_to_occurrence"  [var-annotated]
src/sentry/snuba/metrics/datasource.py:318: error: Need type annotation for "tag_or_value_ids_per_metric_id"  [var-annotated]
src/sentry/replays/usecases/replay_counts.py:137: error: Need type annotation for "replay_id_to_issue_map"  [var-annotated]
src/sentry/utils/committers.py:77: error: Need type annotation for "to_cache"  [var-annotated]
src/sentry/integrations/mixins/issues.py:352: error: Need type annotation for "annotations_by_group_id"  [var-annotated]
src/sentry/api/serializers/models/team.py:262: error: Need type annotation for "project_map"  [var-annotated]
src/sentry/api/serializers/models/team.py:274: error: Need type annotation for "external_teams_map"  [var-annotated]
src/sentry/api/serializers/models/release.py:488: error: Need type annotation for "release_projects"  [var-annotated]
src/sentry/api/serializers/models/release.py:502: error: Need type annotation for "platforms_by_project"  [var-annotated]
src/sentry/api/serializers/models/project.py:119: error: Need type annotation for "project_to_teams"  [var-annotated]
src/sentry/api/serializers/models/project.py:187: error: Need type annotation for "environments_by_project"  [var-annotated]
src/sentry/api/serializers/models/project.py:201: error: Need type annotation for "projects_by_org"  [var-annotated]
src/sentry/api/serializers/models/project.py:205: error: Need type annotation for "features_by_project"  [var-annotated]
src/sentry/api/serializers/models/project.py:391: error: Need type annotation for "platforms_by_project"  [var-annotated]
src/sentry/api/serializers/models/project.py:635: error: Need type annotation for "teams_by_project_id"  [var-annotated]
src/sentry/api/serializers/models/commit.py:123: error: Need type annotation for "releases_by_commit"  [var-annotated]
src/sentry/api/serializers/models/organization_member/base.py:63: error: Need type annotation for "external_users_map"  [var-annotated]
src/sentry/api/serializers/models/organization_member/expand/projects.py:50: error: Need type annotation for "team_ids_by_member_id"  [var-annotated]
src/sentry/api/serializers/models/organization_member/expand/projects.py:63: error: Need type annotation for "projects_by_team_id"  [var-annotated]
src/sentry/api/helpers/group_index/update.py:96: error: Need type annotation for "groups_to_delete"  [var-annotated]
src/sentry/api/helpers/group_index/delete.py:174: error: Need type annotation for "groups_by_project_id"  [var-annotated]
src/sentry/incidents/endpoints/serializers/incident.py:46: error: Need type annotation for "incident_projects"  [var-annotated]
src/sentry/incidents/endpoints/serializers/incident.py:70: error: Need type annotation for "incident_activities"  [var-annotated]
src/sentry/workflow_engine/endpoints/serializers.py:217: error: Need type annotation for "conditions"  [var-annotated]
src/sentry/workflow_engine/endpoints/serializers.py:231: error: Need type annotation for "action_map"  [var-annotated]
src/sentry/workflow_engine/endpoints/serializers.py:296: error: Need type annotation for "ds_map"  [var-annotated]
src/sentry/workflow_engine/endpoints/serializers.py:314: error: Need type annotation for "workflows_map"  [var-annotated]
src/sentry/workflow_engine/endpoints/serializers.py:457: error: Need type annotation for "dcg_map"  [var-annotated]
src/sentry/workflow_engine/endpoints/serializers.py:461: error: Need type annotation for "detectors_map"  [var-annotated]
src/sentry/tasks/check_am2_compatibility.py:587: error: Need type annotation for "unsupported_widgets"  [var-annotated]
src/sentry/tasks/check_am2_compatibility.py:588: error: Need type annotation for "ondemand_supported_widgets"  [var-annotated]
src/sentry/search/snuba/backend.py:52: error: Need type annotation for "types_to_actors"  [var-annotated]
src/sentry/search/snuba/backend.py:176: error: Need type annotation for "types_to_owners"  [var-annotated]
src/sentry/rules/processing/delayed_processing.py:749: error: Need type annotation for "rules_to_slow_conditions"  [var-annotated]
src/sentry/rules/history/preview.py:168: error: Need type annotation for "group_activity"  [var-annotated]
src/sentry/rules/history/preview.py:331: error: Need type annotation for "group_ids"  [var-annotated]
src/sentry/rules/history/preview.py:332: error: Need type annotation for "event_ids"  [var-annotated]
src/sentry/rules/history/preview.py:429: error: Need type annotation for "condition_types"  [var-annotated]
src/sentry/rules/history/preview.py:438: error: Need type annotation for "filtered_activity"  [var-annotated]
src/sentry/releases/endpoints/organization_release_meta.py:94: error: Need type annotation for "platforms_by_project"  [var-annotated]
src/sentry/profiles/flamegraph.py:380: error: Need type annotation for "profiler_metas_by_profiler"  [var-annotated]
src/sentry/notifications/api/endpoints/user_notification_details.py:34: error: Need type annotation for "results"  [var-annotated]
src/sentry/issues/endpoints/organization_event_details.py:33: error: Need type annotation for "group_to_span_map"  [var-annotated]
src/sentry/issues/endpoints/group_integrations.py:47: error: Need type annotation for "issues_by_integration"  [var-annotated]
src/sentry/ingest/transaction_clusterer/tree.py:158: error: Need type annotation for "children_by_name"  [var-annotated]
src/sentry/api/endpoints/organization_trace_item_attributes_ranked.py:134: error: Need type annotation for "cohort_1_distribution_map"  [var-annotated]
src/sentry/api/endpoints/organization_trace_item_attributes_ranked.py:143: error: Need type annotation for "cohort_2_distribution_map"  [var-annotated]
src/sentry/api/endpoints/organization_events_trace.py:692: error: Need type annotation for "occurrence_issue_ids"  [var-annotated]
src/sentry/api/endpoints/organization_events_trace.py:693: error: Need type annotation for "occurrence_ids"  [var-annotated]
src/sentry/api/endpoints/organization_events_trace.py:1368: error: Need type annotation for "parent_to_children_event_map"  [var-annotated]
src/sentry/api/endpoints/organization_events_trace.py:1389: error: Need type annotation for "parent_error_map"  [var-annotated]
src/sentry/api/endpoints/internal/warnings.py:28: error: Need type annotation for "groups"  [var-annotated]
src/sentry/tasks/summaries/daily_summary.py:93: error: Need type annotation for "users_by_tz"  [var-annotated]
src/sentry/releases/use_cases/release.py:126: error: Need type annotation for "platforms"  [var-annotated]
src/sentry/release_health/release_monitor/metrics.py:41: error: Need type annotation for "aggregated_projects"  [var-annotated]
src/sentry/release_health/release_monitor/metrics.py:104: error: Need type annotation for "aggregated_projects"  [var-annotated]
src/sentry/monitors/serializers.py:215: error: Need type annotation for "serialized_monitor_environments"  [var-annotated]
src/sentry/api/endpoints/artifact_bundles.py:144: error: Need type annotation for "grouped_bundles"  [var-annotated]
src/sentry/workflow_engine/migrations/0085_crons_link_detectors_to_all_workflows.py:29: error: Need type annotation for "detectors_by_project"  [var-annotated]
src/sentry/workflow_engine/migrations/0084_crons_dedupe_workflows.py:19: error: Need type annotation for "rules_by_org"  [var-annotated]
src/sentry/workflow_engine/migrations/0084_crons_dedupe_workflows.py:43: error: Need type annotation for "rule_hashes"  [var-annotated]
src/sentry/migrations/0925_backfill_open_periods.py:141: error: Need type annotation for "activities"  [var-annotated]
src/sentry/api/endpoints/release_thresholds/release_threshold_status_index.py:311: error: Need type annotation for "release_threshold_health"  [var-annotated]
src/sentry/incidents/endpoints/serializers/workflow_engine_detector.py:282: error: Need type annotation for "detector_id_to_workflow_ids"  [var-annotated]
src/sentry/incidents/endpoints/serializers/workflow_engine_detector.py:290: error: Need type annotation for "workflow_id_to_action_ids"  [var-annotated]
src/sentry/incidents/endpoints/serializers/workflow_engine_detector.py:294: error: Need type annotation for "detector_to_action_ids"  [var-annotated]
tests/sentry/taskworker/test_client.py:78: error: Need type annotation for "_responses"  [var-annotated]
tests/sentry/buffer/test_redis.py:208: error: Need type annotation for "project_ids_to_rule_data"  [var-annotated]

Expected Behavior

I'm not sure exactly but I feel like this shouldn't have suddenly appeared.

Actual Behavior

see above

Your Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongpendingIssues that may be closedtopic-pluginsThe plugin API and ideas for new plugins

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions