Does `field_specifier` support non-keyword arguments?
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 35/100
- Issue 類型
- 文件
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- python
研究方向
從 dataclass_transform 規範及其 field_specifiers 定義著手;比較 pyrefly、pyright、mypy 和 ty 中的位置引數與關鍵字引數範例。確定是否應允許位置引數,然後在 typing specification 中記錄這項決定;如果專案有相應範例或一致性測試,則新增一個。
由索引模型根據 Issue 內容生成。
描述
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).
- 主要語言
- Python
- 星號
- 1.8k
- 分支
- 302
- 平均合併
- 23 小時
- 30 天內合併 PR
- 8
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/typing 的其他 Issue
-
topic: typing spec
難度 2/5 1-3 小時 新手友好度 72/100
-
topic: typing spec
難度 2/5 1-3 小時 新手友好度 75/100
-
topic: documentation
難度 2/5 1-3 小時 新手友好度 76/100
-
topic: documentation
難度 2/5 1-3 小時 新手友好度 65/100
-
topic: conformance tests topic: typing spec
難度 3/5 1-2 天 新手友好度 72/100
相似的 Issue
-
triage/confirmed
難度 2/5 1-3 小時 新手友好度 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
難度 1/5 1 小時以內 新手友好度 92/100
NousResearch/hermes-agent#118866 ·
-
bug
難度 1/5 1 小時以內 新手友好度 90/100
apache/cloudstack#14222 ·
-
難度 2/5 1-3 小時 新手友好度 76/100
-
bug
難度 2/5 1-3 小時 新手友好度 82/100