Skip to content

Commit

Permalink
Fixed infinite recursion in #89
Browse files Browse the repository at this point in the history
robot.planner or robot.actions not being defined caused infinite
recursion in __getattr__. This patch explicitly checks for those
attributes before querying them.
  • Loading branch information
Michael Koval committed Apr 5, 2015
1 parent c11b02c commit 896a2d8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/prpy/base/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

class Robot(openravepy.Robot):
def __init__(self, robot_name=None):
self.actions = None
self.planner = None
self.robot_name = robot_name

Expand Down Expand Up @@ -80,25 +81,31 @@ def __dir__(self):

# Add planning and action methods to the tab-completion list.
method_names = set(self.__dict__.keys())
method_names.update(self.planner.get_planning_method_names())
method_names.update(self.actions.get_actions())

if hasattr(self, 'planner') and self.planner is not None:
method_names.update(self.planner.get_planning_method_names())
if hasattr(self, 'actions') and self.actions is not None:
method_names.update(self.actions.get_actions())

return list(method_names)

def __getattr__(self, name):
# We have to manually perform a lookup in InstanceDeduplicator because
# __methods__ bypass __getattribute__.
self = bind.InstanceDeduplicator.get_canonical(self)

# Resolve planner calls through the robot.planner field.
if self.planner.has_planning_method(name):
if (hasattr(self, 'planner') and self.planner is not None
and self.planner.has_planning_method(name)):

delegate_method = getattr(self.planner, name)
@functools.wraps(delegate_method)
def wrapper_method(*args, **kw_args):
return self._PlanWrapper(delegate_method, args, kw_args)

return wrapper_method
elif self.actions.has_action(name):
elif (hasattr(self, 'actions') and self.actions is not None
and self.actions.has_action(name)):

delegate_method = self.actions.get_action(name)
@functools.wraps(delegate_method)
def wrapper_method(obj, *args, **kw_args):
Expand Down

0 comments on commit 896a2d8

Please sign in to comment.