Skip to content

Commit d4b7f97

Browse files
authored
Merge pull request #404 from asaffifee/patch-1
Pass the `move` object to the `do_action()` method
2 parents 93bfb7f + 4e62fd0 commit d4b7f97

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

patterns/behavioral/chaining_method.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33

44
class Person:
5-
def __init__(self, name: str, action: Action) -> None:
5+
def __init__(self, name: str) -> None:
66
self.name = name
7-
self.action = action
87

9-
def do_action(self) -> Action:
10-
print(self.name, self.action.name, end=" ")
11-
return self.action
8+
def do_action(self, action: Action) -> Action:
9+
print(self.name, action.name, end=" ")
10+
return action
1211

1312

1413
class Action:
@@ -26,8 +25,8 @@ def stop(self) -> None:
2625
def main():
2726
"""
2827
>>> move = Action('move')
29-
>>> person = Person('Jack', move)
30-
>>> person.do_action().amount('5m').stop()
28+
>>> person = Person('Jack')
29+
>>> person.do_action(move).amount('5m').stop()
3130
Jack move 5m then stop
3231
"""
3332

0 commit comments

Comments
 (0)