Skip to content
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

All python components that wrap a bool now implement __bool__ #5400

Merged
merged 4 commits into from
Mar 5, 2024

Conversation

Wumpf
Copy link
Member

@Wumpf Wumpf commented Mar 5, 2024

What

This fixes unexpected errors with python truthiness.

plus some mypy linting fixes for issues I encountered when running pixi run lint-py-mypy on windows

Checklist

  • I have read and agree to Contributor Guide and the Code of Conduct
  • I've included a screenshot or gif (if applicable)
  • I have tested the web demo (if applicable):
  • The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG
  • If applicable, add a new check to the release checklist!

Copy link
Member

@abey79 abey79 left a comment

Choose a reason for hiding this comment

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

Well done!

@@ -633,6 +633,20 @@ fn code_for_struct(
code.push_indented(1, quote_init_method(reporter, obj, ext_class, objects), 2);
}

// Generate __bool__ operator if this is a single field struct with a bool field.
if fields.len() == 1 && fields[0].typ == Type::Bool {
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if we have to restrict this to bool.

Definitely not as critical as the bool case, but for types that contain an int, for example, it would be nice to have 0 act Falsey as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmmm 🤔
Another time maybe

@Wumpf Wumpf merged commit d23c977 into main Mar 5, 2024
25 of 26 checks passed
@Wumpf Wumpf deleted the andreas/python-bool-operator branch March 5, 2024 14:32
@emilk emilk changed the title All python components that wrap a bool now implement __bool__ All python components that wrap a bool now implement __bool__ Apr 5, 2024
@emilk emilk changed the title All python components that wrap a bool now implement __bool__ All python components that wrap a bool now implement __bool__ Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants