Add __bool__ for classes that implement __nonzero__

__nonzero__ has been renamed to __bool__ in python3.4. So add the
__bool__ magic method that will in turn call the existing __nonzero__
method. This avoids the scheduler going into an infinte loop when
it checks for the no. of tasks remaining.

partial blueprint heat-python34-support

Change-Id: I5de554805a2af9abc15808427ce489720287f6b3
This commit is contained in:
Sirushti Murugesan 2015-06-29 09:05:43 +05:30
parent 46233d2c2a
commit f1f4d60e0a
2 changed files with 8 additions and 0 deletions

View File

@ -71,6 +71,10 @@ class Node(object):
'''Return True if this node is not a leaf (it requires other nodes).'''
return bool(self.require)
def __bool__(self):
'''Return True if this node is not a leaf (it requires other nodes).'''
return self.__nonzero__()
def stem(self):
'''Return True if this node is a stem (required by nothing).'''
return not bool(self.satisfy)

View File

@ -283,6 +283,10 @@ class TaskRunner(object):
"""Return True if there are steps remaining."""
return not self.done()
def __bool__(self):
"""Return True if there are steps remaining."""
return self.__nonzero__()
def wrappertask(task):
"""