Skip to content

Files

Latest commit

 

History

History
27 lines (18 loc) · 470 Bytes

invalid-bool-returned.md

File metadata and controls

27 lines (18 loc) · 470 Bytes

Pattern: __bool__ does not return bool

Issue: -

Description

Used when a __bool__ method returns something which is not a bool.

Example of incorrect code:

class BadBool(object):
    """ __bool__ returns an integer """

    def __bool__(self):  # [invalid-bool-returned]
        return 1

Example of correct code:

class GoodBool(object):
    """__bool__ returns <type 'bool'>"""

    def __bool__(self):
        return True