`_GenericAlias` caches origin's `__module__`
オープン
まだ誰も着手していません。
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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Lib/typing.py のリンク先の _GenericAlias 実装から始め、Python 3.11 で報告された A[T] の例を再現してください。エイリアスの module がどのように取得されるかを追跡し、その後、A.module の変更が既存の typing の動作を壊さずにエイリアスへ反映されることを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100