functools.partial objects cannot be used as `Dynamics.StateMachine.State` methods (onset, ongoing, etc.)
Issue #41
resolved
Creating a basic functools.partial
object and assigning it to a State method, like:
def my_func(argument):
print(argument)
sm.AddState("NewState", onset=partial(my_func, "new_state_onset"))
produces an error:
AttributeError: 'functools.partial' object has no attribute '__get__'
Comments (3)
-
-
reporter Clarification: it only happens when
partial
is used on a bound class method. My bad, I didn’t actually test the basic example I initially gave.This does produce the error:
import Shady from functools import partial class MyClass: def __init__(self, message_prefix): self.message_prefix = message_prefix def flexible_onset(self, message): print(self.message_prefix + message) def add_to_state_machine(self, state_machine, state_name, message): state_machine.AddState(state_name, onset=partial(self.flexible_onset, message)) if __name__ == '__main__': c = MyClass("Prefix: ") sm = Shady.StateMachine() c.add_to_state_machine(sm, "MyState", "Suffix") sm.AddState("MyState2", onset=partial(c.flexible_onset, "Suffix")) # ALSO ERROR
-
- changed status to resolved
fixed in 654b50e (master branch)
- Log in to comment
I cannot replicate this with Shady 1.13.1 (git 79355e0 2020-12-02) on Python 3.7.3 for macOS 10.13 or on Python 3.7.6 for Windows 10.
Although it is true, on these Python versions, that the
partial
object has no__get__
:So Shady 1.13.1 must be handling this contingency. I cannot replicate this problem even by rolling back to 1.8.x (early 2019). Double-check your
python -m Shady --versions