Skip to content

New enum features in Python 3.11 #12841

Description

@AlexWaygood

There's a ton of new enum features in Python 3.11 that mypy doesn't yet support:

  • enum.property
  • enum.verify
  • enum.(non)member
  • ReprEnum
  • StrEnum

enum.property is not yet supported:


The new enum.verify decorator isn't supported: the following snippet will raise an exception at runtime on 3.11 due to not all values being unique, but it passes mypy:

fromenumimportEnum, verify, UNIQUE@verify(UNIQUE)classColor(Enum):
RED=1GREEN=2BLUE=3CRIMSON=1

enum.member/enum.nonmember. The docs are a bit thin on these, but it looks like in the following enum, BAR is converted to become a member, but BAZ
is not:

fromenumimportEnum, nonmemberclassFoo(Enum):
BAR=1BAZ=nonmember(2)

(These two can also be used as decorators)


ReprEnum: this doesn't need any special support by mypy, but the following mypy bug but means that it can't really be used idiomatically at the moment:


StrEnum: I didn't think this required any special treatment from mypy, but there's a weird bug here in mypy's handling of StrEnum:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions