Does `field_specifier` support non-keyword arguments?
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 302
- 平均マージ
- 23時間
- マージ済み PR(30日)
- 8
説明
I was reading through the specification of dataclass_transform and it doesn't really specify what field_specifiers looks like. It mostly just says:
field_specifiers (tuple[Callable[..., Any], ...]) – Specifies a static list of supported classes or functions that describe fields, similar to dataclasses.field(). Defaults to ().
But dataclasses.field takes keyword-only arguments, which leaves it a bit ambiguous about whether positional arguments are ok. For example:
from typing import dataclass_transform, Any
def custom_field(default: object, *, init: bool = True) -> Any: ...
@dataclass_transform(field_specifiers=(custom_field,))
def build(x): ...
@build
class A:
x: int = custom_field(default=0)
@build
class B:
x: int = custom_field(0)
A()
B()
pyrefly, pyright, and mypy all flag B() as an error while ty accepts it without complaint.
My (uninformed) take is that this should be allowed -- custom_field(default=0) and custom_field(0) have the same runtime effect, so it feels like they should have the same type-checking effect too. This also matches how pydantic and attrs works (e.g. you can do pydantic.Field(1) and attr.ib(0)) -- today I suspect the type-checkers are special-casing this to make pydantic and attrs (since I've definitely used both without running into static type-checking errors about missing default values before).
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
dataclass_transform 仕様と、その field_specifiers の定義から始め、pyrefly、pyright、mypy、ty における位置引数とキーワード引数の例を比較します。位置引数を許可すべきかどうかを判断し、その決定を typing specification に記載して、プロジェクトに対応する例または conformance test がある場合はそれを追加します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- documentation
- issue の種類
- ドキュメント
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100