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

FBT001 exclude operators like __and__, __or__ and __xor__, etc. #14202

Closed
randolf-scholz opened this issue Nov 8, 2024 · 4 comments · Fixed by #14203
Closed

FBT001 exclude operators like __and__, __or__ and __xor__, etc. #14202

randolf-scholz opened this issue Nov 8, 2024 · 4 comments · Fixed by #14203
Labels
rule Implementing or modifying a lint rule

Comments

@randolf-scholz
Copy link
Contributor

FBT001 should probably by default exclude methods used for operator overloading, in particular boolean logic specific operations:

  • __and__, __rand__, __iand__
  • __or__, __ror__, __ior__
  • __xor__, __rxor__, __ixor__

And potentially also arithmetic operations like __add__, __sub__, __mul__, etc. (These may add overloads / type hints for boolean values)

@dylwil3 dylwil3 added the rule Implementing or modifying a lint rule label Nov 10, 2024
@dylwil3
Copy link
Collaborator

dylwil3 commented Nov 10, 2024

This is an interesting idea! I guess one question I have is: if you are defining one of the Boolean magic methods for MyClass, why would the other parameter be a bool (as opposed to MyClass? Similarly for arithmetic operations.

I'd be interested to see examples of this in code out in the wild.

@MichaReiser
Copy link
Member

An other option would be to ignore methods marked with @overload

@randolf-scholz
Copy link
Contributor Author

randolf-scholz commented Nov 10, 2024

@dylwil3 A typical example are custom scalar/vector/tensor classes/protocols.

For instance, a BooleanArray might define __or__(self, other: bool | Self) -> Self.

@dylwil3
Copy link
Collaborator

dylwil3 commented Nov 10, 2024

Alright that makes sense to me- thanks for the example! I'm in favor of adopting this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants