class decorator syntax seems to ignore dataclasses' constructor signatures
オープン
まだ誰も着手していません。
bug
topic-dataclasses
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
This code sample gives errors on the presence of f in X's constructor but not on DX's
from __future__ import annotations
from typing import Callable, Type
from dataclasses import dataclass
def clsdec(x: Callable[[int, str, object], object]) -> Type:
return x # type: ignore
@clsdec
class X(object):
def __init__(self, x: int, y: str, z: object, f: float) -> None:
pass
@clsdec
@dataclass
class DX(object):
x: int
y: str
z: object
f: float
It seems like it can't "see" the dataclass's fields somehow, despite otherwise reporting sensible errors at the call site.
In fact, clsdec(DX) gives the same error; it's only a problem when it's used in the decorator position.
Your Environment
- Mypy version used: mypy 0.961 (compiled: yes)
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: Python 3.10.4 (python.org)
- Operating system and version:
ProductName: macOS
ProductVersion: 12.4
BuildVersion: 21F79
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された例を mypy 0.961 で実行し、デコレータ位置の場合の診断結果を直接の clsdec(DX) 呼び出しと比較します。デコレータと dataclass のシグネチャ処理を追跡します。完了条件は、両方の形式でコンストラクタシグネチャのチェックが同等になり、回帰テストでカバーされていることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100