Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TypedDict? #296

Closed
ericbn opened this issue Aug 14, 2022 · 3 comments
Closed

Support TypedDict? #296

ericbn opened this issue Aug 14, 2022 · 3 comments

Comments

@ericbn
Copy link
Contributor

ericbn commented Aug 14, 2022

  • 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'}.

@Tinche
Copy link
Member

Tinche commented Aug 15, 2022

We don't support it currently, but we definitely should. Just haven't gotten around to it.

@Tinche
Copy link
Member

Tinche commented May 20, 2023

This is in PR now (#364), very close.

@Tinche
Copy link
Member

Tinche commented May 22, 2023

Fixed on main.

@Tinche Tinche closed this as completed May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants