setting Sentinel __nonzero__/__bool__ alias and also adding a test for sentinel falsiness

This commit is contained in:
Mahmoud Hashemi 2017-02-15 02:10:55 -08:00
parent ef8a5ca025
commit 2ff30aefe0
2 changed files with 12 additions and 2 deletions

View File

@ -53,8 +53,11 @@ def make_sentinel(name='_MISSING', var_name=None):
def __reduce__(self):
return self.var_name
def __len__(self):
return 0
def __nonzero__(self):
return False
__bool__ = __nonzero__
return Sentinel()

7
tests/test_typeutils.py Normal file
View File

@ -0,0 +1,7 @@
from boltons.typeutils import make_sentinel
def test_sentinel_falsiness():
not_set = make_sentinel('not_set')
assert not not_set