Skip to content

Commit bdad269

Browse files
committed
impl more warnings
1 parent ba462e1 commit bdad269

File tree

4 files changed

+230
-254
lines changed

4 files changed

+230
-254
lines changed

Lib/test/test_warnings/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,6 @@ def test_filter(self):
929929
self.assertRaises(UserWarning, self.module.warn,
930930
'convert to error')
931931

932-
@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module 'warnings' has no attribute 'onceregistry'
933932
def test_onceregistry(self):
934933
# Replacing or removing the onceregistry should be okay.
935934
global __warningregistry__
@@ -959,7 +958,6 @@ def test_onceregistry(self):
959958
finally:
960959
self.module.onceregistry = original_registry
961960

962-
@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module 'warnings' has no attribute 'defaultaction'
963961
def test_default_action(self):
964962
# Replacing or removing defaultaction should be okay.
965963
message = UserWarning("defaultaction test")
@@ -1631,7 +1629,6 @@ def __del__(self):
16311629
self.assertEqual(err.decode().rstrip(),
16321630
'<string>:7: UserWarning: test')
16331631

1634-
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: b'' doesn't start with b'<sys>:0: ResourceWarning: unclosed file '
16351632
def test_late_resource_warning(self):
16361633
# Issue #21925: Emitting a ResourceWarning late during the Python
16371634
# shutdown must be logged.

crates/vm/src/stdlib/warnings.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ pub fn warn(
88
stack_level: usize,
99
vm: &VirtualMachine,
1010
) -> PyResult<()> {
11-
// TODO: use rust warnings module
12-
if let Ok(module) = vm.import("warnings", 0)
13-
&& let Ok(func) = module.get_attr("warn", vm)
14-
{
15-
func.call((message, category.to_owned(), stack_level), vm)?;
16-
}
17-
Ok(())
11+
crate::warn::warn(
12+
vm.new_pyobj(message),
13+
Some(category.to_owned()),
14+
stack_level as isize,
15+
None,
16+
vm,
17+
)
1818
}
1919

2020
#[pymodule]

crates/vm/src/vm/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ declare_const_name! {
247247
_defaultaction,
248248
_onceregistry,
249249
_showwarnmsg,
250+
defaultaction,
251+
onceregistry,
250252
filters,
251253
backslashreplace,
252254
close,

0 commit comments

Comments
 (0)