Skip to content

Commit 75c27bf

Browse files
authored
Merge pull request faif#436 from danwald/update-delegation
Highlight the need for a wrapper in delegate
2 parents 9016858 + ce06e8b commit 75c27bf

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

patterns/fundamental/delegation_pattern.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ class Delegator:
1919
>>> delegator.p2
2020
Traceback (most recent call last):
2121
...
22-
AttributeError: 'Delegate' object has no attribute 'p2'
22+
AttributeError: 'Delegate' object has no attribute 'p2'. Did you mean: 'p1'?
2323
>>> delegator.do_something("nothing")
2424
'Doing nothing'
25+
>>> delegator.do_something("something", kw=", faif!")
26+
'Doing something, faif!'
2527
>>> delegator.do_anything()
2628
Traceback (most recent call last):
2729
...
28-
AttributeError: 'Delegate' object has no attribute 'do_anything'
30+
AttributeError: 'Delegate' object has no attribute 'do_anything'. Did you mean: 'do_something'?
2931
"""
3032

3133
def __init__(self, delegate: Delegate) -> None:
@@ -47,8 +49,8 @@ class Delegate:
4749
def __init__(self) -> None:
4850
self.p1 = 123
4951

50-
def do_something(self, something: str) -> str:
51-
return f"Doing {something}"
52+
def do_something(self, something: str, kw=None) -> str:
53+
return f"Doing {something}{kw or ''}"
5254

5355

5456
if __name__ == "__main__":

0 commit comments

Comments
 (0)