Setting many types of values to `category` argument of `warnings.simplefilter()` doesn't get any error
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
Setting Warning to category argument of warnings.filterwarnings() works, then setting the str type value "Hello World" to category argument of warnings.filterwarnings() gets the error message as shown below. *This is an understandable behavior:
import warnings
warnings.resetwarnings()
warnings.filterwarnings(action="ignore", category=Warning)
print(warnings.filters)
# [('ignore', None, <class 'Warning'>, None, 0)]
warnings.filterwarnings(action="ignore", category="Hello World") # Error
print(warnings.filters)
AssertionError: category must be a class
But, setting many types of values to category argument of warnings.simplefilter() doesn't get any error as shown below. *This isn't an understandable behavior:
import warnings
warnings.simplefilter(action="default", category=Warning) # Understandable
warnings.simplefilter(action="default", category="Hello World") # Not understandable
warnings.simplefilter(action="default", category=100) # Not understandable
warnings.simplefilter(action="default", category=3.14) # Not understandable
warnings.simplefilter(action="default", category=3.14+0.j) # Not understandable
warnings.simplefilter(action="default", category=True) # Not understandable
print(warnings.filters)
# [('default', None, True, None, 0),
# ('default', None, (3.14+0j), None, 0),
# ('default', None, 100, None, 0),
# ('default', None, 'Hello World', None, 0),
# ('default', None, <class 'Warning'>, None, 0)]
So, category argument of warnings.simplefilter() should also return the error message as shown below:
AssertionError: category must be a class
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
- gh-136303
- gh-136305
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從報告中展示的入口 warnings.simplefilter() 和 warnings.filterwarnings() 開始,比較它們各自如何驗證 category 引數。使用無效值重現這些範例,並確認 simplefilter() 會引發與 filterwarnings() 相同的 category 驗證錯誤。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100