Skip to content

Fixed test_bytearray_translate Error#3730

Merged
youknowone merged 3 commits into
RustPython:mainfrom
Lithium07z:fixByteArray
May 22, 2022
Merged

Fixed test_bytearray_translate Error#3730
youknowone merged 3 commits into
RustPython:mainfrom
Lithium07z:fixByteArray

Conversation

@Lithium07z

Copy link
Copy Markdown
Contributor

FileName: test_builtin.py
FunctionName: test_bytearray_translate
Error: RustPython was throwing wrong Error, RustPython was throwing TypeError

FileName: test_builtin.py
FunctionName: test_bytearray_translate
Error: RustPython was throwing wrong Error, RustPython was throwing TypeError

Signed-off-by: Lithium07z <Lithium@hallym.ac.kr>
Comment thread vm/src/bytesinner.rs Outdated
Comment thread vm/src/bytesinner.rs Outdated
|| Ok((0..=255).collect::<Vec<u8>>()),
|v| {
|v: PyObjectRef| {
let v: PyBytesInner = v.try_into_value(vm).map_err(|_| {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The error handling part can be shared

                let bytes = v
                    .try_into_value::<PyBytesInner>(vm)
                    .ok()
                    .filter(|v| v.elements.len() == 256)
                    .ok_or_else(|| {
                        vm.new_value_error(
                            "translation table must be 256 characters long".to_owned(),
                        )
                    })?;
                Ok(bytes.elements.to_vec())

Lithium07z and others added 2 commits May 22, 2022 10:17
FileName: bytesinner.rs
Reason: The error handling part can be shared, so merged it two of error handling parts

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thank you for contributing!

@youknowone youknowone merged commit 53185cd into RustPython:main May 22, 2022
@Lithium07z Lithium07z deleted the fixByteArray branch May 22, 2022 05:27
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