Skip to content

Commit 4de23f6

Browse files
author
Michael Koval
committed
Fixed __getattr__ and __dir__ on Manipulator (#89)
1 parent e2f0839 commit 4de23f6

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/prpy/base/manipulator.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,36 +40,46 @@ def CloneBindings(self, parent):
4040
pass
4141

4242
def __dir__(self):
43+
robot = self.GetRobot()
44+
4345
# We have to manually perform a lookup in InstanceDeduplicator because
4446
# __methods__ bypass __getattribute__.
4547
self = bind.InstanceDeduplicator.get_canonical(self)
4648

4749
# Add planning methods to the tab-completion list.
4850
method_names = set(self.__dict__.keys())
49-
method_names.update(self.GetRobot().planner.get_planning_method_names())
50-
method_names.update(self.GetRobot().actions.get_actions())
51+
52+
if hasattr(robot, 'planner') and robot.planner is not None:
53+
method_names.update(robot.planner.get_planning_method_names())
54+
if hasattr(robot, 'actions') and robot.actions is not None:
55+
method_names.update(robot.actions.get_actions())
56+
5157
return list(method_names)
5258

5359
def __getattr__(self, name):
5460
# We have to manually perform a lookup in InstanceDeduplicator because
5561
# __methods__ bypass __getattribute__.
5662
self = bind.InstanceDeduplicator.get_canonical(self)
63+
robot = self.GetRobot()
5764

5865
# Resolve planner calls through the robot.planner field.
5966
# FIXME: We need to replicate the _PlanWrapper functionality here.
60-
if self.GetRobot().planner.has_planning_method(name):
61-
delegate_method = getattr(self.GetRobot().planner, name)
67+
if (hasattr(robot, 'planner') and robot.planner is not None
68+
and robot.planner.has_planning_method(name)):
69+
70+
delegate_method = getattr(robot.planner, name)
6271
@functools.wraps(delegate_method)
63-
def wrapper_method(*args, **kw_args):
64-
return self._PlanWrapper(delegate_method, args, kw_args)
72+
def wrapper_method(*args, **kwargs):
73+
return self._PlanWrapper(delegate_method, args, kwargs)
6574
return wrapper_method
66-
elif self.GetRobot().actions.has_action(name):
67-
delegate_method = self.GetRobot().actions.get_action(name)
75+
76+
elif (hasattr(robot, 'actions') and robot.actions is not None
77+
and robot.actions.has_action(name)):
78+
79+
delegate_method = robot.actions.get_action(name)
6880
@functools.wraps(delegate_method)
69-
def wrapper_method(obj, *args, **kw_args):
70-
return delegate_method(self.GetRobot(), obj,
71-
manip = self,
72-
*args, **kw_args)
81+
def wrapper_method(obj, *args, **kwargs):
82+
return delegate_method(robot, obj, manip=self, *args, **kwargs)
7383
return wrapper_method
7484

7585
raise AttributeError('{0:s} is missing method "{1:s}".'.format(repr(self), name))

0 commit comments

Comments
 (0)