Conformance suite: Questionable tests in dataclasses_descriptors.py
@ashishpatel26 已經在處理了。
開始於 2026年6月1日。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 48/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 冷清
- 技術堆疊
- python
- 領域
- testing-qa
研究方向
閱讀 conformance/tests/dataclasses_descriptors.py,重點關注 issue 中描述的 Desc2 和 DC2 案例。根據執行期行為以及 pyrefly、mypy 和 pyright 的不同結果,檢查斷言的型別。完成的標準是:conformance suite 不再要求執行期行為未規範或不支援的行為,且由專案維護者解決刪除測試的提案。
由索引模型根據 Issue 內容生成。
描述
The dataclasses_descriptors.py test case has a comment "This portion of the dataclass spec is under-specified in the documentation, but its behavior can be determined from the runtime implementation."
However, some of the behaviors in tests don't align with the runtime behavior.
The first part, which is using a data descriptor Desc1 and a dataclass DC1, is fine.
Then we get this, where Desc2 is a non-data descriptor (only implementing __get__):
@dataclass
class DC2:
x: Desc2[int]
y: Desc2[str]
z: Desc2[str] = Desc2()
assert_type(DC2.x, list[int])
assert_type(DC2.y, list[str])
assert_type(DC2.z, list[str])
However, DC2.x and DC2.y are AttributeErrors at runtime, because there is no Desc2 object in the runtime class dictionary. I don't know if we should require type checkers to produce an error but certainly we should allow it.
Then we construct a DC2 object:
dc2 = DC2(Desc2(), Desc2(), Desc2())
assert_type(dc2.x, int)
assert_type(dc2.y, str)
assert_type(dc2.z, str)
But at runtime, dc2's three attributes are all just those Desc2 objects, not ints or strs, because those objects are stored as instance attributes, so the descriptor protocol never runs on them.
The more complicated case is the z attribute, which has a Desc2 object stored in the class. Dataclasses would conventionally treat this as the default, but it gets the default by conventional access in the class body, which calls the descriptor's __get__ with obj=None. So the runtime default for this field is actually the value you'd get for accessing DC2.z, which is list[str].
Looking at actual type checker behavior, I think pyrefly gets all this pretty much right (which means it fails the test). Mypy and pyright pass the test, but their behavior is wrong.
Since (as the test acknowledges) the behavior is not fully specified, perhaps it is best to delete this test from the conformance suite for now, until we come up with a full specification for the behavior of descriptors in dataclasses.
- 主要語言
- Python
- 星號
- 1.8k
- 分支
- 302
- 平均合併
- 4 小時 38 分鐘
- 30 天內合併 PR
- 6
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 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
-
Update reference/generics.html with PEP695 type parameter syntax可能已有人在做 @BHUVANSH855 於 181 天前認領。 未關閉topic: documentation
難度 2/5 1-3 小時 新手友好度 76/100
-
topic: documentation
難度 2/5 1-3 小時 新手友好度 65/100
-
Finals and Literals: Spec contradiction可能已有人在做 @srittau 於 34 天前認領。 未關閉topic: conformance tests topic: typing spec
難度 3/5 1-2 天 新手友好度 72/100
相似的 Issue
-
needs triage
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
json_params_matcher fails on falsy top-level JSON primitives (0, False, "")可能已有人在做 @mayureshsonawane17 今天認領。 未關閉Waiting for: Product Owner
難度 2/5 1-3 小時 新手友好度 84/100
維護者通常 5 天內回覆
-
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
ayghri/i-have-adhd#249 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
modelscope/FunASR#3762 ·
維護者通常 1 天內回覆