From 00b3ece69d4aa1a5479465e88e4051f8abd10738 Mon Sep 17 00:00:00 2001 From: Jim Crist-Harif Date: Thu, 18 Jan 2024 11:14:42 -0600 Subject: [PATCH] fix(api): deferred values are not truthy --- ibis/common/deferred.py | 5 +++++ ibis/common/tests/test_deferred.py | 8 ++++++++ 2 files changed, 13 insertions(+) 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):