Skip to content

"Expected TypedDict key to be string literal" false positive? #4122

Closed
@jstasiak

Description

@jstasiak

Shouldn't something like this work?

from mypy_extensions import TypedDict

Details = TypedDict('Details', {'first_name': str, 'last_name': str})
DetailsSubset = TypedDict('DetailsSubset', {'first_name': str, 'last_name': str}, total=False)
defaults = {'first_name': 'John', 'last_name': 'Luther'}  # type: Details


def generate(data: DetailsSubset) -> Details:
    return {**defaults, **data}

I'm getting:

% mypy code.py 
code.py: error: Expected TypedDict key to be string literal

Oh, and the error message is missing the line number, that could be handy to have.

I'm using mypy 0.530 and Python 3.6.2.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions