Skip to content

Support TypedDict? #296

@ericbn

Description

@ericbn
  • cattrs version: 22.1.0
  • Python version: 3.9.13
  • Operating System: macOS 12.5

Description

I know cattrs does not currently support TypedDict. Is this something that would make sense as a new feature?

I want to convert an input dict into an output dict, ideally with a structure defined as a TypedDict. Each value in the input dict should be converted to the correspondent type in the TypedDict definition. The problem was described in https://stackoverflow.com/q/65196658/2654518.

What I Did

from typing import TypedDict

import cattrs


class Test(TypedDict):
    value: int


cattrs.structure({'value': '42', 'foo': 'bar'}, Test)

With TypedDict support, the output would be {'value': 42}, instead of {'value': '42', 'foo': 'bar'}.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions