`_GenericAlias` caches origin's `__module__`
未關閉
還沒有人認領這個 Issue。
topic-typing
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
When subscripting a class, __module__ gets saved. This prevents fixing it up later:
https://github.com/python/cpython/blob/4c3f0cbeaec0d49212d305618743fabb0e74a696/Lib/typing.py#L1411
from typing import Generic, TypeVar
T = TypeVar("T")
class A(Generic[T]):
pass
x = A[T] # this originally was in ... somewhere, but is here for minimization
A.__module__ = "new_module"
assert x.__module__ == "new_module" # this is going to raise AssertionError
This came up when updating the Sphinx version in trio due to our handling of private/public. We update __module__ for these classes in __init__ (to make Sphinx work, among other things) but this doesn't end up updating any stored _GenericAliass' __module__s.
CPython versions tested on:
3.11
Operating systems tested on:
Windows
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 Lib/typing.py 中連結的 _GenericAlias 實作開始,並在 Python 3.11 上重現回報的 A[T] 範例。追蹤如何取得 alias 的 module,然後驗證變更 A.module 會反映到 alias 中,同時不會破壞 typing 的既有行為。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100