Indexing a Type Alias of an Enum yields false error
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Minimum [not-]working product:
Ah, good old Enums:
from enum import Enum
class EnumClass(Enum):
one = 1
EnumAlias = EnumClass
EnumAlias['one']
test.py:6: error: Type application targets a non-generic function or class
test.py:6: error: Name 'one' is not defined
I'm fairly certain this is not an intentional design choice. Just to be sure, according to documentation:
A type alias does not create a new type. It’s just a shorthand notation for another type – it’s equivalent to the target type except for generic aliases.
Now, Enums actually can't be generic, so I certainly expect the alias to be equivalent. So I think this code should pass (regardless of its usefulness... who wants to alias an Enum anyways?).
Possible Causes
I'm no expert, but I think this is happening because the semantic analyzer deems any IndexExpr a TypeApplication if it has a TypeAlias as a base. Once it's marked as analyzed, it doesn't reach the stage of the expression checker where the Enum type would be recognized and the indexing processed as valid. Whatever the root of the problem, I think there's only one spot where the expression checker actually looks at is_enum to handle Enum indexing, so the alias isn't making it there one way or another.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、基底が TypeAlias の場合にセマンティックアナライザーが IndexExpr を TypeApplication として分類する仕組みを追跡し、次に is_enum を処理する式チェッカーの経路を追ってください。EnumAlias['one'] の例で、報告されていた2つのエラーがどちらも発生しなくなっていることを確認し、このケースの回帰テストを追加してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100