Skip to content

Support TypedDict update() with keyword arguments #6019

Open

Description

@JukkaL

Things like d.update(x=1, y=2) should be accepted if d is a TypedDict and the keys and values are compatible.

Activity

  1. emmatyping commented on Dec 28, 2024

    @emmatyping
    Member

    I think this would need to be added as a specification of the standard. I do not see this as allowed anywhere, and currently the update method is annotated as accepting only a TypedDict in typeshed.

    Perhaps this should be moved to the typing repo (or I guess CPython)?

  2. JelleZijlstra commented on Dec 28, 2024

    @JelleZijlstra
    Member

    I don't think this would require a change to the spec. The spec is mostly silent on the update() method (there is some discussion from the ReadOnly PEP at https://typing.readthedocs.io/en/latest/spec/typeddict.html#update-method), but it wouldn't be against the spec to allow update() calls that preserve the type. Pyright also accepts it: https://pyright-play.net/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoAqiApgCYAiSAxjAFC1UA2AhgM6tQAaAFEQmZRoBKAFy0oEqMxGYUdWqWLAowbgA8ZnUeMlqAdAFcEpZjGLdmAXgCMQ2kA

    Perhaps this should be moved to the typing repo (or I guess CPython)?

    The CPython issue tracker should only be used for tracking changes to the typing.py runtime. Spec changes should go to the python/typing issue tracker.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions