python / python/cpython

typing._GenericAlias objects allow arbitrary dunder attribute creation

オープン
#136,731 コメント 8 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib topic-typing type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

Objects like typing.List[int] allow arbitrary dunders to be set, and because of the cache, those attributes can leak to other objects created elsewhere in the program:

>>> x = List[int]
>>> x.__whatever__ = 42
>>> List[int].__whatever__
42

The cache behavior seems like it could lead to undesirable behavior. In 3.14 we somewhat accidentally fixed a similar bug with Union objects, and it turns out some people were relying on this: #132139. Let's think about whether we also want to remove this wart for other typing objects in 3.15.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず issue の typing.List[int] の例を再現し、generic aliases の実装とテストを調べます。ファイルやテストの名前は指定されていません。最初に、任意の dunder 属性とキャッシュされた typing オブジェクトについて意図された動作を確立し、その後、オブジェクト間で属性が漏れず、動作が一貫していることを示す回帰テストを追加します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
developer-experience
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。