python / python/cpython

warnings: adding new filter resets prior existing "once" filters

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

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

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

説明

Bug report

Bug description:

If a filter is defined with action="once", the occurrence tracking is reset each time a new filter is defined. This can override the ability to effectively use action="once" if the filter manipulation occurs in a library which the user cannot control (e.g. matplotlib).

For example, the following code will only output a warning once (i.e. works as intended):

import warnings

warnings.filterwarnings("once", "test warning", UserWarning)
warnings.warn("test warning", UserWarning)
warnings.warn("test warning", UserWarning)

However, simply inserting an unrelated filter prior to the second warning will cause both to be output:

warnings.filterwarnings("once", "test warning", UserWarning)
warnings.warn("test warning", UserWarning)

warnings.filterwarnings("ignore", "something unrelated")
warnings.warn("test warning", UserWarning)
CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs
  • gh-153697

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

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

はじめの一歩

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

調査の方向性

Issue にある warnings.filterwarnings と warnings.warn の再現コードから始め、その後 CPython 内の warnings の実装とテストを特定します。既存の action="once" フィルターについて、無関係なフィルターを追加しても発生回数の追跡がリセットされなくなれば完了です。gh-153697 はすでにこの issue にリンクされています。

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

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

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

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