diff --git a/ibis/common/deferred.py b/ibis/common/deferred.py index 03bf7eb3b948..17290ba4aaa6 100644 --- a/ibis/common/deferred.py +++ b/ibis/common/deferred.py @@ -97,6 +97,11 @@ def __getattr__(self, name): def __iter__(self): raise TypeError(f"{self.__class__.__name__!r} object is not iterable") + def __bool__(self): + raise TypeError( + f"The truth value of {self.__class__.__name__} objects is not defined" + ) + def __getitem__(self, name): return Deferred(Item(self, name)) diff --git a/ibis/common/tests/test_deferred.py b/ibis/common/tests/test_deferred.py index df6a0a343be8..616eebb47097 100644 --- a/ibis/common/tests/test_deferred.py +++ b/ibis/common/tests/test_deferred.py @@ -501,6 +501,14 @@ def test_deferred_is_not_iterable(obj): next(obj) +@pytest.mark.parametrize("obj", [_, _.a, _.a.b[0]]) +def test_deferred_is_not_truthy(obj): + with pytest.raises( + TypeError, match="The truth value of Deferred objects is not defined" + ): + bool(obj) + + def test_deferrable(table): @deferrable def f(a, b, c=3):