`filterwarnings` causes `warnings.warn` to raise `TypeError` on non-string messages
Bug report
When using filterwarnings, a TypeError is raised when a non-string value is passed to warnings.warn which differs from the default behavior of warnings.warn.
import warnings # Does not raise a type error warnings.warn(1) # Raises a type error with warnings.catch_warnings(): warnings.filterwarnings("ignore", "test") warnings.warn(1)
The traceback does not demonstrate that this is a detail of warning filtering:
/Users/mz/eng/src/madkinsz/cpython-103577/example.py:4: UserWarning: 1 warnings.warn(1) Traceback (most recent call last): File "/Users/mz/eng/src/madkinsz/cpython-103577/example.py", line 9, in <module> warnings.warn(1) TypeError: expected string or bytes-like object
Filtering warnings should not change the accepted types of warnings.warn.
Reproduction example at https://github.com/madkinsz/cpython-103577
Originally raised at pytest-dev/pytest#10865
Your environment
Reproduced Ubuntu with Python 3.7-3.12: https://github.com/madkinsz/cpython-103577/actions/runs/4714383423/jobs/8360711980
Also reproduced manually on macOS with Python 3.10/3.11