bool(Lea) doesn't raise an exception

Issue #34 closed
Paul Moore created an issue

From the code in lea.py it looks like bool(lea_value) is intended to raise an exception, but it doesn't seem to do so:

>>> from lea import Lea
>>> bool(Lea.fromVals(True))
True
>>> bool(Lea.fromVals(False))
True

Comments (8)

  1. Paul Moore reporter

    This is because the __nonzero__ method is named __bool__ in Python 3. Adding __bool__ = __nonzero__ fixes this.

  2. Pierre Denis repo owner

    Well spotted! You're perfectly right. I'll do the fix that you suggest, although in a converse way because I prefer the cleaner Python 3 to be the baseline:

        def __bool__(self):   ## <--- renamed!
            raise ...
        # Python 2 compatibility
        __nonzero__ = __bool__
    

    You can see this pattern for Lea.__div__ and Lea.__rdiv__.

  3. Log in to comment