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

Allow TypedDict key with literal type during construction #7645

Merged
merged 2 commits into from Oct 7, 2019

Conversation

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 7, 2019

Also refactored an operation away from mypy.plugins.common so that it
is more cleanly reusable. Also kept an alias in the original location
to avoid breaking existing plugins.

Fixes #7644.

Refactored an operation away from `mypy.plugins.common` so that it
is more cleanly reusable. Also kept an alias in the original location
to avoid breaking existing plugins.

Fixes #7644.
@JukkaL JukkaL requested a review from ilevkivskyi Oct 7, 2019
Copy link
Collaborator

ilevkivskyi left a comment

Thanks, LGTM! Just one comment about tests.

num2: Literal['num']
v = {num2: 2}
bad2: Literal['bad']
v = {bad: 2} # E: Expected TypedDict key to be string literal

This comment has been minimized.

Copy link
@ilevkivskyi

ilevkivskyi Oct 7, 2019

Collaborator

I suppose this should be bad2, otherwise bad2 would be unused in this test.

for lit in get_proper_types(possible_literals):
if isinstance(lit, LiteralType) and lit.fallback.type.fullname() == 'builtins.str':
val = lit.value
assert isinstance(val, str)

This comment has been minimized.

Copy link
@b0g3r

b0g3r Oct 7, 2019

It's not a review comment, just my curiosity: why is this needed?

This comment has been minimized.

Copy link
@JukkaL

JukkaL Oct 7, 2019

Author Collaborator

Mypy thinks that the value could be an integer, for example, since it doesn't understand the fullname() check above.

@JukkaL JukkaL merged commit 7bbc7af into master Oct 7, 2019
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@JelleZijlstra JelleZijlstra deleted the tdict-key-literal branch Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.