提交 61c3957b authored 作者: David Warde-Farley's avatar David Warde-Farley 提交者: Arnaud Bergeron

implement __bool__ where __nonzero__ exists.

上级 3c6d4240
......@@ -284,6 +284,11 @@ class Keyword:
self.nonzero = nonzero
def __nonzero__(self):
# Python 2.x
return self.__bool__()
def __bool__(self):
# Python 3.x
return self.nonzero
def __str__(self):
......
......@@ -67,7 +67,12 @@ class _tensor_py_operators:
rval._is_nonzero = False
return rval
def __nonzero__(self):
# Python 2.x
return self.__bool__()
def __bool__(self):
# This is meant to prohibit stuff like a < b < c, which is internally
# implemented as (a < b) and (b < c). The trouble with this is the
# side-effect that checking for a non-NULL a by typing "if a: ..."
......@@ -75,6 +80,8 @@ class _tensor_py_operators:
# it seems impossible. Currently, all vars evaluate to nonzero except
# the return values of comparison operators, which raise this
# exception. If you can think of a better solution, go for it!
#
# __bool__ is Python 3.x data model. __nonzero__ is Python 2.x.
if self._is_nonzero:
return True
else:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论