Comment 0 for bug 603951

Revision history for this message
Eike (eike-welk) wrote :

Currently both arguments of the boolean operators "and" and "or" are evaluated at compile time. impement short cut semantics because everybody expects this.

Possible solutions:
- Follow Python's implementation closely:
    - At compile time call argument.__bool__() and decide in special purpose code.
    - For generated code use special function which is converted by code generator back into shortcut
      operator. (Similar to current implementation.)

- Implement idea from Greg Ewing (PEP 335: http://www.python.org/dev/peps/pep-0335/):
        -Special methods for boolean operators 'and', 'or'
              To retain the shortcut semantics split the execution of the
              operator into two phases:
              - first call __and1__(self), __or1__(self) if these operators
                can compute the result they return True/False; otherwise they
                return the special value NeedOtherOperand.
              - if NeedOtherOperand was returned call:
                __and2__(self, other), __rand2__(self, other)
                __or2__(self, other), __ror2__(self, other)
              - Calls with unknown arguments always end up as: __xx2__
                (this is implemented)