Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions crates/vm/src/stdlib/_warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,12 @@ mod _warnings {
category: Option<PyObjectRef>,
vm: &VirtualMachine,
) -> PyResult<Option<PyTypeRef>> {
if message.fast_isinstance(vm.ctx.exceptions.warning) {
return Ok(Some(message.class().to_owned()));
}
let cat_obj = match category {
Some(c) if !vm.is_none(&c) => c,
_ => {
return Ok(if message.fast_isinstance(vm.ctx.exceptions.warning) {
Some(message.class().to_owned())
} else {
None // will default to UserWarning in warn_explicit
});
}
_ => return Ok(None), // will default to UserWarning in warn_explicit
};

let cat = PyTypeRef::try_from_object(vm, cat_obj.clone()).map_err(|_| {
Expand Down
17 changes: 17 additions & 0 deletions extra_tests/snippets/stdlib_warnings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
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
Comment on lines +18 to +20

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the new assertions from the test file

These lines add new assertions and test logic to an existing test file, but this repository explicitly prohibits modifying test assertions, logic, or data and limits acceptable test-file edits to adding or removing expected-failure markers; this test-file portion of the commit therefore needs to be removed or handled through an approved non-test-file mechanism.

AGENTS.md reference: AGENTS.md:L275-L279

Useful? React with 👍 / 👎.

Loading