Skip to content

Conversation

evanrittenhouse
Copy link
Contributor

New PR for #4374. Still working on figuring out how to get the error messages to match, but wanted to get this up to at least run against CI and see what else I'm missing. I think the general direction should be okay.

@evanrittenhouse evanrittenhouse changed the title Implement logic - errors not working Implement strict_mode keyword for binascii.a2b_base64() Jan 19, 2023
@evanrittenhouse evanrittenhouse marked this pull request as ready for review February 19, 2023 18:06
@evanrittenhouse
Copy link
Contributor Author

@DimitrisJim was wondering if you could help me out. cargo run -- Lib/test/test_binascii.py passes locally, but it seems like some of the binascii tests are failing here. Is there a difference? I'm also unsure why test_ioctl, test_urllib, etc. would be failing if I haven't done any work on them.

Thanks for all your help so far!

@fanninpm
Copy link
Contributor

I believe you can use the following command to test your changes locally:

# this runs all of the tests (not necessary if you know which test is affected)
cargo run --release --features ssl,jit -- -m test -j 1 -u all --slowest --fail-env-changed -v
# this runs only the test suite named "test_whatever" (usually located at `Lib/test/test_whatever.py`)
cargo run --release --features ssl,jit -- -m test -j 1 -u all --slowest --fail-env-changed -v test_whatever

For a list of all resources and more command-line options, you can execute cargo run --release --features ssl,jit -- -m test -h.

@DimitrisJim
Copy link
Member

DimitrisJim commented Feb 20, 2023

Seems like test_urllib has a test that indirectly uses the changes. (test_ioctl seems to just be skipped after glancing through the ci logs so you can ignore that).

As @fanninpm mentioned, you should use -- -m test to run these (running with cargo run -- Lib/test/test_binascii.py might not invoke the test runner in the same way, as far as I can tell).

I'll try and make some time to check through the code to see if I can spot where any issues might be and thanks for working on it!

@evanrittenhouse
Copy link
Contributor Author

Looks like test_urllib is failing because we're not checking for Incorrect padding. It's marked as an expected failure in test_binascii.py, so that's what I'm working on now

@evanrittenhouse
Copy link
Contributor Author

@DimitrisJim I think (fingers crossed) this is done?

Ok(decoded)
})
.map_err(|err| {
let python_error = match err {
Copy link
Member

Choose a reason for hiding this comment

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

impl ToPyException for base64::DecodeError is possible to replace this block

Copy link
Contributor Author

@evanrittenhouse evanrittenhouse Feb 28, 2023

Choose a reason for hiding this comment

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

Sorry, pretty new to Rust. Could you please provide an example in the context of the repo? Not super sure how to apply it in practice, sorry

Copy link
Member

Choose a reason for hiding this comment

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

io.rs in vm/src/stdlib contains an implementation of ToPyException for Io::Errorwhich can definitely serve as a good example. You basically just move the match in there and use to_pyexception here.

Copy link
Member

Choose a reason for hiding this comment

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

We have a trait called ToPyException which used to convert any error to python exception. It is used to convert Io::Error to python exception as @DimitrisJim explained.
Once you implement it, this code will look like:

        .map_err(|err| err.to_pyexception(vm))

If you stuck with it, please feel free to ask anything again or tell us to take over that part.

The patch is really nice and this suggestion is totally optional. You don't need to finish to implement ToPyException to finish this PR.

Thank you!

Copy link
Contributor Author

@evanrittenhouse evanrittenhouse Mar 4, 2023

Choose a reason for hiding this comment

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

Thanks for the kind words! I'm not sure I'll be able to get it

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.

Thank you for contributing! I appended a commit with a little of changes

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.

4 participants