Skip to content

StrEnum not recognized as a string by dictionary update #11354

@acampove

Description

@acampove

Describe the bug
When using update, to update a dictionary, the keys of the dictionary are StrEnum, but pyright complains because it expects a str

Code or Screenshots

from enum import StrEnum

class Region(StrEnum):
    NORTH = "north"
    SOUTH = "south"
    EAST = "east"
    WEST = "west"

d1 = {Region.NORTH : 3}
d2 = {'one': 1, 'two' : 2}

d2.update(d1)

That shows me:

WARNING: there is a new pyright version available (v1.1.407 -> v1.1.408).
Please install the new version or set PYRIGHT_PYTHON_FORCE_VERSION to `latest`

/home/acampove/Tests/pyright/str_enum/test.py
  /home/acampove/Tests/pyright/str_enum/test.py:16:1 - error: No overloads for "update" match the provided arguments (reportCallIssue)
  /home/acampove/Tests/pyright/str_enum/test.py:16:11 - error: Argument of type "dict[Region, int]" cannot be assigned to parameter "m" of type "Iterable[tuple[str, int]]" in function "update"
    "dict[Region, int]" is not assignable to "Iterable[tuple[str, int]]"
      Type parameter "_T_co@Iterable" is covariant, but "Region" is not a subtype of "tuple[str, int]"
        "Region" is not assignable to "tuple[str, int]" (reportArgumentType)
2 errors, 0 warnings, 0 informations

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