Skip to content

Commit ade29d6

Browse files
committed
Added type hints to chaining method pattern
1 parent e639308 commit ade29d6

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

patterns/behavioral/chaining_method.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1+
from __future__ import annotations
2+
3+
14
class Person:
2-
def __init__(self, name, action):
5+
def __init__(self, name: str, action: Action) -> None:
36
self.name = name
47
self.action = action
58

6-
def do_action(self):
9+
def do_action(self) -> Action:
710
print(self.name, self.action.name, end=" ")
811
return self.action
912

1013

1114
class Action:
12-
def __init__(self, name):
15+
def __init__(self, name: str) -> None:
1316
self.name = name
1417

15-
def amount(self, val):
18+
def amount(self, val: str) -> Action:
1619
print(val, end=" ")
1720
return self
1821

19-
def stop(self):
22+
def stop(self) -> None:
2023
print("then stop")
2124

2225

0 commit comments

Comments
 (0)