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

from enum import StrEnum

class Choices(StrEnum):
    LOREM = "lorem"
    IPSUM = "ipsum"

# This is ok
def ok_func() -> list[Choices]:
    return list(Choices)

# However this produces an error
def error_func() -> list[Choices]:
    var = list(Choices)
    return var

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions