python / python/mypy

New enum features in Python 3.11

Open
#12,841 5 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature meta topic-enum
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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:

  • #12483

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:

  • #12787

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:

  • #14688

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing mypy's existing handling of Python enums and the Python 3.11 enum documentation. Use the issue's examples for enum.verify and enum.member/nonmember to determine the expected behavior, then verify that the listed unsupported features are handled consistently while accounting for the separately linked issues.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.