Files
RustPython/extra_tests/snippets/stdlib_warnings.py
youknowdot 7079e70b79 Honor warning instance categories before validating category arguments (#9034)
Extract the Python 3.14-compatible ordering fix from #8954. An existing Warning instance determines its own category, regardless of the category argument. Keep canonical invalid-category coverage and add only the missing instance case to the existing warnings snippet.

Assisted-by: OpenAI Codex:model identifier unavailable
2026-10-10 19:36:20 +09:00

21 lines
452 B
Python

import _warnings
_warnings.warn("Test")
import warnings
class CustomWarning(UserWarning):
pass
for category in (None, DeprecationWarning, int, 42):
message = CustomWarning("sentinel")
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
warnings.warn(message, category)
assert len(caught) == 1
assert caught[0].message is message
assert caught[0].category is CustomWarning