Make NOTHING falsey (#732)
* Make NOTHING falsey Fixes #720 * Add newsfragment * Python 2
This commit is contained in:
parent
3d274d0bfa
commit
f132c07e55
|
@ -0,0 +1 @@
|
|||
``bool(attr.NOTHING)`` is now ``False``.
|
|
@ -69,6 +69,12 @@ class _Nothing(object):
|
|||
def __repr__(self):
|
||||
return "NOTHING"
|
||||
|
||||
def __bool__(self):
|
||||
return False
|
||||
|
||||
def __len__(self):
|
||||
return 0 # __bool__ for Python 2
|
||||
|
||||
|
||||
NOTHING = _Nothing()
|
||||
"""
|
||||
|
|
|
@ -808,6 +808,13 @@ class TestNothing(object):
|
|||
assert not (_Nothing() != _Nothing())
|
||||
assert 1 != _Nothing()
|
||||
|
||||
def test_false(self):
|
||||
"""
|
||||
NOTHING evaluates as falsey.
|
||||
"""
|
||||
assert not NOTHING
|
||||
assert False is bool(NOTHING)
|
||||
|
||||
|
||||
@attr.s(hash=True, order=True)
|
||||
class C(object):
|
||||
|
|
Loading…
Reference in New Issue