python / python/mypy

New enum features in Python 3.11

オープン
#12,841 コメント 5 件 リアクション 6 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature meta topic-enum
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、mypy における Python enum の既存の処理と、Python 3.11 の enum ドキュメントを確認してください。issue にある enum.verify と enum.member/nonmember の例を使って期待される動作を判断し、別途リンクされている issue を考慮しつつ、一覧にある未対応機能が一貫して処理されることを確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
devtools
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。