Skip to content

Add BaseException.__reduce__ #3665

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

Merged
merged 6 commits into from
Apr 29, 2022
Merged

Conversation

fanninpm
Copy link
Contributor

Addresses three items in #3611.

cc @Snowapril

@Snowapril
Copy link
Contributor

Looks good! This PR can be a good specimen for the other remaining works. Does "three items" mean OSError, ImportError, BaseException?

@fanninpm
Copy link
Contributor Author

Does "three items" mean OSError, ImportError, BaseException?

Yes. I only had to add things to BaseException, since ImportError and OSError inherit from BaseException.

@Snowapril
Copy link
Contributor

@fanninpm
Copy link
Contributor Author

Unfortunately, OSError's and ImportError's reduce act different than BaseException's 😭

I would direct future contributors to look at the extend_exception! macro.

@Snowapril
Copy link
Contributor

Ok good 😊. Except for the issue about the empty set that I commented on, everything seems fine.

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, thank you! @Snowapril and thank you for the review!

@@ -519,6 +519,15 @@ impl PyBaseException {
let cls = zelf.class();
format!("{}({})", cls.name(), repr_args.iter().format(", "))
}

#[pymethod(magic)]
fn reduce(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyTupleRef {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it doesn't require type checking, this may be:

Suggested change
fn reduce(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyTupleRef {
fn reduce(zelf: PyObjectRef, vm: &VirtualMachine) -> PyTupleRef {

Copy link
Contributor Author

@fanninpm fanninpm Apr 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work in practice because rustc will complain:

no method named `args` found for struct `core::PyObjectRef` in the current scope
method not found in `core::PyObjectRef`

@fanninpm fanninpm requested a review from youknowone April 29, 2022 14:59
@youknowone youknowone merged commit 4c39668 into RustPython:main Apr 29, 2022
@fanninpm fanninpm deleted the baseexception-reduce branch April 29, 2022 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants