Skip to content

Support dict(name=x, ...) #239

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
JukkaL opened this issue Jul 15, 2013 · 4 comments
Closed

Support dict(name=x, ...) #239

JukkaL opened this issue Jul 15, 2013 · 4 comments
Labels

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 15, 2013

Support dict(name=x, ...) in the type checker. Infer key type as str and value type based on keyword argument types.

We can't represent the signature of dict precisely using current functionality alone, i.e. we need some new type checker functionality.

@ghost ghost assigned JukkaL Dec 24, 2013
@JukkaL JukkaL removed the front end label Jul 25, 2014
@JukkaL JukkaL removed their assignment Jul 25, 2014
@JukkaL
Copy link
Collaborator Author

JukkaL commented Oct 12, 2014

The common case should actually be pretty easy to implement by just special casing this in the semantic analyzer and using the analyzed attribute of the dict(...) CallExpr to store a DictExpr when the call only uses keyword arguments. The dict literal keys should be string literals generated from the keyword argument names, and the dict values are just the argument expressions.

The **args case is trickier, but this seems rare so we don't need to support it yet.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Aug 23, 2015

Increasing priority as this is actually a pretty common issue.

@gvanrossum
Copy link
Member

Yeah, I see this a lot in our latest demo project.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Nov 22, 2015

This now works but for heterogeneous dictionaries the inferred type will likely be Dict[str, object] unless there is an explicit type annotation, so this isn't super useful yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants