Wrong Signature for Enum with Specific Dataclass Mixin Scenario
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 5.1k
- フォーク
- 2.1k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 82
説明
Note: I was thinking about putting this on pyright but it said standard library problems are more suited here, so I'll give it a shot.
I was trying to code an enum with a dataclass mixin where each value is overridden through the first string variable for easier referencing (rather than a dict from str to enum).
from dataclasses import dataclass
from enum import Enum, auto
@dataclass(frozen=True)
class SampleMixin:
a_string: str
a_number: int
class SampleEnum(SampleMixin, Enum):
def __new__(cls, value: str, *_):
obj = object.__new__(cls)
obj._value_ = value
return obj
foo = "foo", 1
bar = "bar", 2
class SampleEnum2(Enum):
foo = auto()
bar = auto()
baz = SampleEnum("foo")
qux = SampleEnum2("foo")
baz still gets SampleEnum.foo right, but the function signature is incorrectly identified. Ideally, it should be closer to SampleEnum2's function signature.
I'm open to workarounds at the meantime. The code runs correctly, it's just that the inferred signature I got was wrong.
Code sample in pyright playground.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Pythonでの再現とリンクされたpyright playgroundから始め、SampleEnumとSampleEnum2について推論されたシグネチャを比較します。typeshedにある標準ライブラリのenumおよびdataclassの関連する型付け定義を追跡し、dataclass-mixinのケースでランタイムの動作を変更せずに意図したenumコンストラクターのシグネチャが生成されることを確認したら、完了とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- developer-experience
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 55/100