Skip to content

Support copy constructor for TypedDict #2738

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

Closed
davidfstr opened this issue Jan 22, 2017 · 3 comments
Closed

Support copy constructor for TypedDict #2738

davidfstr opened this issue Jan 22, 2017 · 3 comments

Comments

@davidfstr
Copy link
Contributor

davidfstr commented Jan 22, 2017

It should be possible to copy a TypedDict via a copy constructor like:

point2 = Point(point1)

Currently this is rejected by the type checker.


It may also be desirable to support the following:

point2d = Point2D(point3d)

...although I'd have to think about whether this is actually typesafe and consistent.


Suggested tags for this issue: feature, topic-typed-dict

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 23, 2017

point2d = Point2D(point3d) should be okay since we have structural subtyping for typed dicts.

@97littleleaf11
Copy link
Collaborator

point2d = Point2D(point3d) would copy every field of point3d during runtime. Let's just focus on the same typeddict first.

@97littleleaf11
Copy link
Collaborator

I just checked the PEP589, non-keyword arguments are not allowed when TypedDict is used as a callable object:

It can be used as a callable object with keyword arguments corresponding to the TypedDict items. Non-keyword arguments are not allowed.

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

3 participants