Skip to content

Commit 2c65499

Browse files
committed
Clean up feedback and fix docs
1 parent 1ba9260 commit 2c65499

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

magicbot/magicrobot.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,39 @@
2121
def feedback(key=None):
2222
"""
2323
If this decorator is applied to a function,
24-
it's return value will automatically be sent
25-
to NetworkTables at key ``/robot/component/component/key``
24+
its return value will automatically be sent
25+
to NetworkTables at key ``/robot/components/component/key``.
2626
2727
``key`` is an optional parameter, and if it is not supplied,
2828
the key will default to the method name with 'get_' removed.
2929
If the method does not start with 'get_', the key will be the full
30-
name of the method
30+
name of the method.
3131
3232
.. note:: The function will automatically be called in disabled,
33-
autonomous, and teleop.
33+
autonomous, and teleop.
3434
3535
.. warning:: The function should only act as a getter, and accept
36-
no arguments.
36+
no arguments.
3737
38-
Example
38+
Example::
3939
40-
class Component1:
41-
42-
@feedback()
43-
def get_angle(self):
44-
return self.navx.getYaw()
40+
class Component1:
4541
42+
@feedback()
43+
def get_angle(self):
44+
return self.navx.getYaw()
4645
4746
In this example, the NetworkTable key is stored at
48-
``/robot/components/component1/angle``
47+
``/robot/components/component1/angle``.
4948
"""
5049
def decorator(func):
51-
if not hasattr(func, '__call__'):
52-
raise ValueError('Illegal use of feedback decorator on {}'.format(func.__name__))
50+
if not callable(func):
51+
raise ValueError('Illegal use of feedback decorator on non-callable {!r}'.format(func))
5352
sig = inspect.signature(func)
5453
name = func.__name__
5554

56-
for i, arg in enumerate(sig.parameters.values()):
57-
if i == 0 and arg.name != 'self':
58-
raise ValueError("First argument to %s must be 'self'" % name)
59-
elif i != 0:
60-
raise ValueError('Only \'self\' is allowed for {}'.format(name))
55+
if len(sig.parameters) != 1:
56+
raise ValueError("{} may not take arguments other than 'self' (must be a simple getter method)".format(name))
6157

6258
nt_key = key
6359
if nt_key is None:
@@ -70,9 +66,9 @@ def decorator(func):
7066
else:
7167
nt_key = name
7268
# Set '__feedback__ attribute to be checked during injection
73-
setattr(func, '__feedback__', True)
69+
func.__feedback__ = True
7470
# Store key within the function to avoid using class dictionary
75-
setattr(func, '__key__', nt_key)
71+
func.__key__ = nt_key
7672
return func
7773
return decorator
7874

0 commit comments

Comments
 (0)