Skip to content

Expected TypedDict key to be string literal when passing {str('foo'): str('bar')} #4029

Closed
@EvanKrall

Description

@EvanKrall
from mypy_extensions import TypedDict


FooDict = TypedDict(
    'FooDict',
    {
        'foo': str,
    },
)


def my_cool_function(arg: FooDict) -> None:
    pass


my_cool_function({"foo": "bar"})
my_cool_function({str("foo"): "bar"})
$ mypy blurp.py
blurp.py:17: error: Expected TypedDict key to be string literal

I understand this is going through the str() function, which is why it's failing, but it seems like this simple case could be handled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions