Skip to content

_StrPromise on a TypedDict #1804

@michjnich

Description

@michjnich

Bug report

What's wrong

If I define a TypedDict

class CustomItem(TypedDict):
    name: str
    value: str

And a dict that uses this:

from django.utils.translation import gettext_lazy as _

MYDICT: dict[str, CustomItem] = {
    "test": {"name": _("testing"), "value": "this"}
}

I get the resulting message:

Incompatible types (expression has type "_StrPromise", TypedDict item "name" has type "str")

I am currently using the django_stubs_ext.StrOrPromise instead here, but the README asks us to report if we come across a _StrPromise issue while using Django.

How is that should be

I should be able to type a gettext_lazy value as str

System information

  • OS: WSL2 on Win11
  • python version: 3.11.6
  • django version: 4.2.6
  • mypy version: 1.6.1
  • django-stubs version: 4.2.6
  • django-stubs-ext version: 4.2.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions