GeezerVison is showing github.com — Refactor warn.rs and _warnings module by youknowone · Pull Request #7023 · RustPython/RustPython
Refactor warn.rs and _warnings module
#7023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.py
(1)
.rs
(4)
All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
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
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
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,
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Uh oh!
There was an error while loading. Please reload this page.
}
#[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
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.