Do Dunder methods (magic methods) exist for `and` and `or` in python?

Viewed 71

There's __and__ and __or__ for & and | respectively, are there modifiable dunders for and and or too?

If so, I can't seem to find them. They are not listed on the docs here: https://docs.python.org/3/reference/datamodel.html

Context: making an api where I want people to be able to do foo and bar and jar, instead of having to do method(method(foo, bar),jar). I can still use & and | but just curious, would prefer the readability of and and or

2 Answers

PEP 335 -- Overloadable Boolean Operators was rejected in 2012, with rejection notice:

We've had many discussions in the past about PEP 335 and they always ended in non-action. I'm cutting any future discussions short and officially rejecting the PEP. Amongst other reasons, I really dislike that the PEP adds to the bytecode for all uses of these operators even though almost no call sites will ever need the feature.

No.

is, and, and or cannot be overloaded.

Related