Skip to content

Support more than just string literals with TypedDict indexing #7867

@wadetregaskis-linkedin

Description

@wadetregaskis-linkedin
from mypy_extensions import TypedDict

T = TypedDict('T', {'a': float, 'b': float, 'c': float})

foo: T = {'a': 0.0, 'b': 0.0, 'c': 0.0}

for key in ('a', 'b', 'c'):
    foo[key] = 1.0

mypy currently (0.730) complains about that last line, saying error: TypedDict key must be a string literal; expected one of ('a', 'b', 'c'). It's understandable, but limiting - it'd be great if mypy could recognise that key is in fact one of the valid keys for T.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy