Skip to content

Commit 392082c

Browse files
author
Christopher Doris
committed
define __bool__ on jlwrap objects
1 parent 101cf77 commit 392082c

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

src/jlwrap/any.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ function init_jlwrap_any()
206206
return ValueBase.__dir__(self) + self._jl_callmethod($(pyjl_methodnum(pyjlany_dir)))
207207
def __call__(self, *args, **kwargs):
208208
return self._jl_callmethod($(pyjl_methodnum(pyjlany_call)), args, kwargs)
209+
def __bool__(self):
210+
return True
209211
def __len__(self):
210212
return self._jl_callmethod($(pyjl_methodnum(pyjlany_op(length))))
211213
def __getitem__(self, k):

src/jlwrap/array.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ function init_jlwrap_array()
304304
return self._jl_callmethod($(pyjl_methodnum(Py copy)))
305305
def reshape(self, shape):
306306
return self._jl_callmethod($(pyjl_methodnum(pyjlarray_reshape)), shape)
307+
def __bool__(self):
308+
return bool(len(self))
307309
def __getitem__(self, k):
308310
return self._jl_callmethod($(pyjl_methodnum(pyjlarray_getitem)), k)
309311
def __setitem__(self, k, v):

src/jlwrap/dict.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ function init_jlwrap_dict()
3838
class DictValue(AnyValue):
3939
__slots__ = ()
4040
_jl_undefined_ = object()
41+
def __bool__(self):
42+
return bool(len(self))
4143
def __iter__(self):
4244
return self._jl_callmethod($(pyjl_methodnum(pyjldict_iter)))
4345
def __contains__(self, key):

src/jlwrap/set.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ function init_jlwrap_set()
7979
$("\n"^(@__LINE__()-1))
8080
class SetValue(AnyValue):
8181
__slots__ = ()
82+
def __bool__(self):
83+
return bool(len(self))
8284
def add(self, value):
8385
return self._jl_callmethod($(pyjl_methodnum(pyjlset_add)), value)
8486
def discard(self, value):

0 commit comments

Comments
 (0)