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
3 changes: 0 additions & 3 deletions Lib/test/test_warnings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,6 @@ def test_filter(self):
self.assertRaises(UserWarning, self.module.warn,
'convert to error')

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

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

@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: b'' doesn't start with b'<sys>:0: ResourceWarning: unclosed file '
def test_late_resource_warning(self):
# Issue #21925: Emitting a ResourceWarning late during the Python
# shutdown must be logged.
Expand Down
12 changes: 4 additions & 8 deletions crates/vm/src/stdlib/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2808,14 +2808,10 @@ mod _io {
encoding: Option<PyUtf8StrRef>,
vm: &VirtualMachine,
) -> PyResult<PyUtf8StrRef> {
if encoding.is_none() && vm.state.config.settings.warn_default_encoding {
crate::stdlib::warnings::warn(
vm.ctx.exceptions.encoding_warning,
"'encoding' argument not specified".to_owned(),
1,
vm,
)?;
}
// Note: Do not issue EncodingWarning here. The warning should only
// be issued by io.text_encoding(), the public API. This function
// is used internally (e.g., for stdin/stdout/stderr initialization)
// where no warning should be emitted.
let encoding = match encoding {
None if vm.state.config.settings.utf8_mode > 0 => {
identifier_utf8!(vm, utf_8).to_owned()
Expand Down
38 changes: 19 additions & 19 deletions crates/vm/src/stdlib/warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ pub fn warn(
stack_level: usize,
vm: &VirtualMachine,
) -> PyResult<()> {
// TODO: use rust warnings module
if let Ok(module) = vm.import("warnings", 0)
&& let Ok(func) = module.get_attr("warn", vm)
{
func.call((message, category.to_owned(), stack_level), vm)?;
}
Ok(())
crate::warn::warn(
vm.new_pyobj(message),
Some(category.to_owned()),
isize::try_from(stack_level).unwrap_or(isize::MAX),
None,
vm,
)
}

#[pymodule]
Expand All @@ -31,18 +31,18 @@ mod _warnings {
vm.state.warnings.filters.clone()
}

#[pyattr(name = "_defaultaction")]
fn default_action(vm: &VirtualMachine) -> PyStrRef {
#[pyattr]
fn _defaultaction(vm: &VirtualMachine) -> PyStrRef {
vm.state.warnings.default_action.clone()
}

#[pyattr(name = "_onceregistry")]
fn once_registry(vm: &VirtualMachine) -> PyDictRef {
#[pyattr]
fn _onceregistry(vm: &VirtualMachine) -> PyDictRef {
vm.state.warnings.once_registry.clone()
}

#[pyattr(name = "_warnings_context")]
fn warnings_context(vm: &VirtualMachine) -> PyObjectRef {
#[pyattr]
fn _warnings_context(vm: &VirtualMachine) -> PyObjectRef {
vm.state
.warnings
.context_var
Expand All @@ -63,21 +63,21 @@ mod _warnings {
.clone()
}

#[pyfunction(name = "_acquire_lock")]
fn acquire_lock(vm: &VirtualMachine) {
#[pyfunction]
fn _acquire_lock(vm: &VirtualMachine) {
vm.state.warnings.acquire_lock();
}

#[pyfunction(name = "_release_lock")]
fn release_lock(vm: &VirtualMachine) -> PyResult<()> {
#[pyfunction]
fn _release_lock(vm: &VirtualMachine) -> PyResult<()> {
if !vm.state.warnings.release_lock() {
return Err(vm.new_runtime_error("cannot release un-acquired lock".to_owned()));
}
Ok(())
}

#[pyfunction(name = "_filters_mutated_lock_held")]
fn filters_mutated_lock_held(vm: &VirtualMachine) {
#[pyfunction]
fn _filters_mutated_lock_held(vm: &VirtualMachine) {
vm.state.warnings.filters_mutated();
}

Expand Down
2 changes: 2 additions & 0 deletions crates/vm/src/vm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ declare_const_name! {
_defaultaction,
_onceregistry,
_showwarnmsg,
defaultaction,
onceregistry,
filters,
backslashreplace,
close,
Expand Down
Loading
Loading