Skip to content

Improve __bool__ #1354

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 5 commits into from
Sep 9, 2019
Merged

Improve __bool__ #1354

merged 5 commits into from
Sep 9, 2019

Conversation

ChJR
Copy link
Contributor

@ChJR ChJR commented Sep 8, 2019

issue founded by @youknowone

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.

Generally it looks good to me

Some(int_obj) => !int_obj.as_bigint().is_zero(),
Some(int_obj) => {
let len_val = int_obj.as_bigint();
if len_val.sign() == Sign::Minus {
Copy link
Member

Choose a reason for hiding this comment

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

Do we prefer to have if-else block than this pattern?

if len_val.sign() == Sign::Minus {
   Err(
      vm.new_value_error("__len__() should return >= 0".to_string())
    )
} else {
    !len_val.is_zero()
}

Copy link
Member

Choose a reason for hiding this comment

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

It would still have to return the error, as the result of that expression is a bool and not a Result.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, it must escape from the function, i got it.

@coolreader18 coolreader18 merged commit b7a11df into RustPython:master Sep 9, 2019
@ChJR ChJR deleted the feature/__bool__ branch September 12, 2019 05:55
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