From 2ff30aefe00a7d6bd7636cbad6d92f03d09cf251 Mon Sep 17 00:00:00 2001 From: Mahmoud Hashemi Date: Wed, 15 Feb 2017 02:10:55 -0800 Subject: [PATCH] setting Sentinel __nonzero__/__bool__ alias and also adding a test for sentinel falsiness --- boltons/typeutils.py | 7 +++++-- tests/test_typeutils.py | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/test_typeutils.py diff --git a/boltons/typeutils.py b/boltons/typeutils.py index 462d408..6a70f22 100644 --- a/boltons/typeutils.py +++ b/boltons/typeutils.py @@ -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() diff --git a/tests/test_typeutils.py b/tests/test_typeutils.py new file mode 100644 index 0000000..80c6cc6 --- /dev/null +++ b/tests/test_typeutils.py @@ -0,0 +1,7 @@ + +from boltons.typeutils import make_sentinel + + +def test_sentinel_falsiness(): + not_set = make_sentinel('not_set') + assert not not_set