GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mypy cannot decide if a cast is necessary or redundant · Issue #21607 · python/mypy

mypy cannot decide if a cast is necessary or redundant #21607

New issue
Copy link
New issue
Copy link
Open
#20444
Open
mypy cannot decide if a cast is necessary or redundant#21607
#20444
Copy link
Labels
bugmypy got something wrongtopic-inferenceWhen to infer types or require explicit annotationstopic-literal-types

Description

@clo-vis
clo-vis
opened on Jun 11, 2026
Issue body actions

Bug Report

Here a case where mypy says a cast is redundant, but if you remove the cast, mypy cannot infer the right type.

To Reproduce

Gist
Playground

Expected Behavior
Either no error with the cast or no error without the cast.

Actual Behavior
Using a type cast, mypy says it's not needed.
Without the type cast, mypy cannot infer the type.

Your Environment

  • Mypy version used: 2.10
  • Mypy configuration options from mypy.ini (and other config files): warn_redundant_casts = true
  • Python version used: 3.14

Activity

  1. clo-vis
    added
    bugmypy got something wrong
    on Jun 11, 2026
  2. ilevkivskyi
    added
    topic-literal-types
    topic-inferenceWhen to infer types or require explicit annotations
    on Jun 12, 2026
  3. CNTRL-tek91 commented on Aug 3, 2026

    @CNTRL-tek91
    CNTRL-tek91
    on Aug 3, 2026
    More actions

    I can work on this and I'll open a PR soon.

  4. CNTRL-tek91 commented on Aug 3, 2026

    @CNTRL-tek91
    CNTRL-tek91
    on Aug 3, 2026
    More actions

    Actually, sorry, this turns out to be the same tension already tracked in #19055 and #19761 (redundant-cast vs. TypeVar literal inference), and there's an open draft PR (#20444) attempting a broader fix. Stepping back from this one since it's still unsettled upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-inferenceWhen to infer types or require explicit annotationstopic-literal-types

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.