FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

`init` debug helper by youknowone · Pull Request #6315 · RustPython/RustPython · GitHub

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

Filter by extension

Filter by extension .rs  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
24 changes: 23 additions & 1 deletion crates/vm/src/types/slot.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -835,14 +835,36 @@ pub trait Initializer: PyPayload {
#[pyslot]
#[inline]
fn slot_init(zelf: PyObjectRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult<()> {
let zelf = zelf.try_into_value(vm)?;
#[cfg(debug_assertions)]
let class_name_for_debug = zelf.class().name().to_string();

let zelf = match zelf.try_into_value(vm) {
Ok(zelf) => zelf,
Err(err) => {
#[cfg(debug_assertions)]
{
if let Ok(msg) = err.as_object().repr(vm) {
let double_appearance =
msg.as_str().matches(&class_name_for_debug as &str).count() == 2;
if double_appearance {
panic!(
"This type `{}` doesn't seem to support `init`. Override `slot_init` instead: {}",
class_name_for_debug, msg
);
}
}
}
return Err(err);
}
};
let args: Self::Args = args.bind(vm)?;
Self::init(zelf, args, vm)
}

#[pymethod]
#[inline]
fn __init__(zelf: PyRef<Self>, args: Self::Args, vm: &VirtualMachine) -> PyResult<()> {
// TODO: check if this is safe. zelf may need to be `PyObjectRef`
Self::init(zelf, args, vm)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/vm/vm_new.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ impl VirtualMachine {
#[cfg(debug_assertions)]
let msg = if class.get_id() == actual_class.get_id() {
let mut msg = msg;
msg += " Did you forget to add `#[pyclass(with(Constructor))]`?";
msg += " It might mean this type doesn't support subclassing very well. e.g. Did you forget to add `#[pyclass(with(Constructor))]`?";
msg
} else {
msg
Expand Down
Loading

Back | FazBrowse Home | New Git URL