Skip to content

Commit 24223eb

Browse files
committed
[Python] Implement truth testing for lldb.value
Python 3 calls __bool__() instead of __len__() and lldb.value only implemented the __len__ method. This adds the __bool__() implementation. Differential revision: https://reviews.llvm.org/D67183 llvm-svn: 370953
1 parent 5559406 commit 24223eb

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lldb/packages/Python/lldbsuite/test/python_api/value/TestValueAPI.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ def test(self):
160160
val_i.GetType()).AddressOf(),
161161
VALID_VARIABLE)
162162

163+
# Check that lldb.value implements truth testing.
164+
self.assertFalse(lldb.value(frame0.FindVariable('bogus')))
165+
self.assertTrue(lldb.value(frame0.FindVariable('uinthex')))
166+
163167
self.assertTrue(int(lldb.value(frame0.FindVariable('uinthex')))
164168
== 3768803088, 'uinthex == 3768803088')
165169
self.assertTrue(int(lldb.value(frame0.FindVariable('sinthex')))

lldb/scripts/Python/python-extensions.swig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,9 @@ class value(object):
980980
def __nonzero__(self):
981981
return self.sbvalue.__nonzero__()
982982

983+
def __bool__(self):
984+
return self.sbvalue.__bool__()
985+
983986
def __str__(self):
984987
return self.sbvalue.__str__()
985988

0 commit comments

Comments
 (0)