FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Allow tighter types with protocols and overloads · Issue #22199 · python/mypy · GitHub

Repository navigation

Allow tighter types with protocols and overloads #22199

Open

Description

Bug Report

I'm not really sure if this is more of a bug or a feature request, but basically I was playing around with TypedDicts and I thought this would be really interesting.

To Reproduce

from typing import TypedDict, Protocol, Callable

class X(TypedDict):
    a: int
    b: str

class GetX[K, V](Protocol):
    def __getitem__(self, key: K, /) -> V: ...

x: X = ...

def f[T, R](k: T, d: GetX[T, R]) -> R:
    return d[k]

reveal_type(x["b"])  # N: Revealed type is "str"
reveal_type(f("b", x))  # N: Revealed type is "object"

Expected Behavior

Both get revealed as str.

Actual Behavior

One gets revealed as object.

Your Environment

Reproduced in mypy-play.

  • Mypy version used: 2.4.0
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.12

Activity

  1. added
    bugmypy got something wrong
    topic-inferenceWhen to infer types or require explicit annotations
    on Oct 13, 2026
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 annotations

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL