| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -341,12 +341,11 @@ impl VirtualMachine { | |
| /// [`vm.invoke_exception()`][Self::invoke_exception] or | ||
| /// [`exceptions::ExceptionCtor`][crate::exceptions::ExceptionCtor] instead. | ||
| pub fn new_exception(&self, exc_type: PyTypeRef, args: Vec<PyObjectRef>) -> PyBaseExceptionRef { | ||
| debug_assert_eq!( | ||
| exc_type.slots.basicsize, | ||
| core::mem::size_of::<PyBaseException>(), | ||
| "vm.new_exception() is only for exception types without additional payload. The given type '{}' is not allowed. Use vm.new_os_subtype_error() for OSError subtypes.", | ||
| exc_type.name() | ||
| ); | ||
| if exc_type.slots.basicsize != core::mem::size_of::<PyBaseException>() { | ||
| // If constructing the exception raises (e.g. __init__ rejects the | ||
| // args), surface that exception instead of panicking. | ||
| return self.invoke_exception(&exc_type, args).unwrap_or_else(|e| e); | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualityunwrap_or_else is wrong folding here. in my opinion, new_exception must not call invoke_exception for a few reason Note: it doesn't mean i am justifying the name new_exception and invoke_exception. if anyone can suggest good names that shows this difference, welcome.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityAgreed on keeping new_exception thin. I prototyped a dedicated payload path that skips PyType::call, for the internal builders that know their type at compile time: pub fn new_payload_exception<T>(&self, cls: PyTypeRef, args: FuncArgs) -> PyResult<PyRef<T>>
where
T: Constructor<Args = FuncArgs> + Initializer,
{
let payload = T::py_new(&cls, args.clone(), self)?;
let exc = payload
.into_ref_with_type_lazy_dict(self, cls)
.expect("new_payload_exception: cls is not a matching subtype of T");
T::slot_init(exc.as_object().to_owned(), args, self)?;
Ok(exc)
}I verified it by routing both StopIteration and OSError through it — behaves identically, vm tests pass, and it simplifies OSErrorBuilder. new_exception stays untouched, and invoke_exception still handles the runtime-typed / user-subclass path. If you're on board with this direction, I'd open it as a separate draft to work on further.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualitysounds good, let's try it
Sorry, something went wrong.
devyubin reacted with thumbs up emoji
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Sorry, something went wrong.
All reactions
|
||
| } | ||
|
|
||
| PyBaseException::new(args, self) | ||
| .into_ref_with_type_lazy_dict(self, exc_type) | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityNit: setting msg here is redundant — slot_init sets it again — and diverges slightly from CPython, where __new__ leaves msg unset (SyntaxError.__new__(SyntaxError, "x").msg is None there, since only __init__ assigns it). msg: None.into() would match.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYou're right about the CPython __new__ behavior, but msg: None.into() brings back a CI failure from earlier in this PR.
Since TabError (a second-level subclass) never reaches PySyntaxError::slot_init, TabError("error", …) renders as TabError: <no detail available> in tracebacks, which breaks test_doctest's test_syntax_error_with_note.
Setting it in py_new is a workaround until slot inheritance works properly for second-level subclasses.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.