Skip to content

Invalid typing assumption over variable with list(StrEnum) on python 3.11 #14688

Description

@Nnonexistent

Bug Report

On python 3.11 using StrEnum, if converting given enum to a list and assigning to a variable, mypy will wrongly assumes that given variable will be list[str], not list[StrEnum].

To Reproduce

fromenumimportStrEnumclassChoices(StrEnum):
LOREM="lorem"IPSUM="ipsum"# This is okdefok_func() ->list[Choices]:
returnlist(Choices)
# However this produces an errordeferror_func() ->list[Choices]:
var=list(Choices)
returnvar

https://mypy-play.net/?mypy=latest&python=3.11&gist=e73a15c8902092236567da4a4567f372

Expected Behavior

Mypy should assume list[Choices] type for var.

Actual Behavior

Incompatible return value type (got "List[str]", expected "List[Choices]") [return-value]

Your Environment

  • Mypy version used: 1.0.0
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.11.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions