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

Literal type not accepted as key when constructing TypedDict #7644

Closed
JukkaL opened this issue Oct 7, 2019 · 1 comment · Fixed by #7645
Closed

Literal type not accepted as key when constructing TypedDict #7644

JukkaL opened this issue Oct 7, 2019 · 1 comment · Fixed by #7645
Assignees
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high topic-typed-dict

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Oct 7, 2019

@b0g3r reported an issue with TypedDict keys not being accepted with literal types. Example code from #6262 (comment):

from mypy_extensions import TypedDict
from typing_extensions import Literal, Final


class MyDict(TypedDict):
    field_name: int

d: MyDict
d = {'field_name': 1}  # OK

name_in_var = 'field_name'
d = {name_in_var: 1}  # Correct error

name_in_literal2: Literal['field_name'] = 'field_name'
d = {name_in_literal2: 1}  # Unexpected error

name_in_final: Final = 'field_name'
d = {name_in_final: 1}  # Unexpected error
@JukkaL JukkaL added bug mypy got something wrong topic-typed-dict priority-0-high false-positive mypy gave an error on correct code labels Oct 7, 2019
@JukkaL JukkaL self-assigned this Oct 7, 2019
JukkaL added a commit that referenced this issue Oct 7, 2019
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.
@b0g3r
Copy link

b0g3r commented Oct 7, 2019

Oh no, I wanted to implement it :(

But thanks anyway!

JukkaL added a commit that referenced this issue 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-0-high topic-typed-dict
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants