Skip to content

New enum features in Python 3.11 #12841

Open

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:

from enum import Enum, verify, UNIQUE

@verify(UNIQUE)
class Color(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3
    CRIMSON = 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:

from enum import Enum, nonmember

class Foo(Enum):
    BAR = 1
    BAZ = 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:

Activity

  1. added
    meta
    on May 22, 2022
  2. electric-coder commented on May 30, 2023

    @electric-coder

    There are 83 open Enum mypy issues at the the time of this writing.

    Getting the Enum datatype to work with mypy is becoming impossible as I find myself having to use cast() in at least every other line.

  3. electric-coder commented on Dec 28, 2023

    @electric-coder

    @AlexWaygood there's also Enum's _new_member_ that hasn't been mentioned in the docs nor in the mypy repository.

  4. CoolCat467 commented on Jun 16, 2024

    @CoolCat467
    Contributor

    With #17376 being merged we should be able to check off enum.nonmember, no?

  5. AlexWaygood commented on Jun 16, 2024

    @AlexWaygood
    MemberAuthor

    With #17376 being merged we should be able to check off enum.nonmember, no?

    Done

  6. CoolCat467 commented on Dec 15, 2025

    @CoolCat467
    Contributor

    As far as I understand it, would StrEnum be checked off now that #18587 was merged?

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

    featuremetatopic-enum

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions