Skip to content

Commit

Permalink
step: set event source for bound methods
Browse files Browse the repository at this point in the history
It is possible to call the step function not via the @step decorator but
directly. In case getattr() is used to retrieve an object's method it
will be a bound method object (instead of a function object when used
via the decorator). The signature of a bound method does not contain self
as a parameter, so the event source will always be None.

Currently only the GraphStrategy calls the step function directly. Fix
the event source in these cases by using func.__self__ for bound methods.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
  • Loading branch information
Bastian-Krause authored and jluebbe committed Jan 15, 2020
1 parent 437a847 commit 9927515
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion labgrid/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def decorator(func):
def wrapper(*_args, **_kwargs):
bound = signature.bind_partial(*_args, **_kwargs)
bound.apply_defaults()
source = bound.arguments.get('self')
source = func.__self__ if inspect.ismethod(func) else bound.arguments.get('self')
step = steps.get_new(title, tag, source)
# optionally pass the step object
if 'step' in signature.parameters:
Expand Down

0 comments on commit 9927515

Please sign in to comment.