Pattern matching a dataclass with different field type fails for Python >= 3.13
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
Pattern matching on a dataclass with a field of different type than required by the dataclass fails with Cannot determine type of ... for Python 3.13 and higher
To Reproduce
3.12 working gist: https://mypy-play.net/?mypy=latest&python=3.12&gist=f2947a04a9a86defefd16e54c0133c84
3.13 failing gist: https://mypy-play.net/?mypy=latest&python=3.13&gist=f2947a04a9a86defefd16e54c0133c84
from dataclasses import dataclass
@dataclass
class A:
pass
@dataclass
class B:
pass
@dataclass
class C:
sth: A
def func(c: C, b: B):
match c:
case C(B() as obj) if obj == b:
print("matched")
Expected Behavior
I believe it should resolve the type same as for <= 3.12.
Actual Behavior
For Python >= 3.13 inferring obj type fails with:
repro.py:17: error: Cannot determine type of "obj" [has-type]
Your Environment
- Mypy version used:
1.19.1 - Mypy command-line flags:
mypy repro.py - Mypy configuration options from
mypy.ini(and other config files): no additional config - Python version used:
3.13.5
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
repro.py の例から始め、リンクされた playground のケースを使って Python 3.12 および 3.13 上で mypy 1.19.1 を実行します。case C(B() as obj) に関係するパターンマッチングと dataclass の推論を追跡します。Python 3.13 が Cannot determine type エラーなしで 3.12 と一貫して obj を推論できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100