Skip to content

Improve representation of TypedDicts #3590

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 Jun 22, 2017 · 1 comment · Fixed by #3598
Closed

Improve representation of TypedDicts #3590

JukkaL opened this issue Jun 22, 2017 · 1 comment · Fixed by #3598

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 22, 2017

reveal_type() used with a TypedDict generates a long output that is quite different from the current syntax for defining a TypedDict. Example:

TypedDict(x=builtins.int, y=builtins.int, z=builtins.int, _fallback=typing.Mapping[builtins.str, builtins.int])

Not sure what's the best course action. Some ideas:

  • Drop fallback if it's a Mapping, since it's at least mostly redundant.
  • Use {'x': builtins.int, ...} instead of x=builtins.int, ....
  • Support the syntax TypedDict('Name', x=int, ...) for defining a TypedDict, so that the supported syntax is closer to reveal_type.
  • Do something about required/non-required keys. The best approach probably depends on other choices.
@JukkaL
Copy link
Collaborator Author

JukkaL commented Jun 22, 2017

It would also be nice to have a better representation for an empty TypedDict type. Maybe TypedDict({})?

JukkaL added a commit that referenced this issue Jun 23, 2017
Change the formatting to be closer to the TypedDict definition syntax
and preserve TypedDict name when constructing using TD(...) for better
reveal_type output.

Note that this uses a new representation `'key'?: type` for
non-required keys.

I'll update remaining error messages to use the new syntax in a
separate PR.

Fixes #3590.
JukkaL added a commit that referenced this issue Jul 4, 2017
Change the formatting to be closer to the TypedDict definition syntax
and preserve TypedDict name when constructing using TD(...) for better
reveal_type output.

Note that this uses a new representation `'key'?: type` for
non-required keys.

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

Successfully merging a pull request may close this issue.

1 participant