Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions patterns/fundamental/delegation_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ class Delegator:
>>> delegator.p2
Traceback (most recent call last):
...
AttributeError: 'Delegate' object has no attribute 'p2'
AttributeError: 'Delegate' object has no attribute 'p2'. Did you mean: 'p1'?
>>> delegator.do_something("nothing")
'Doing nothing'
>>> delegator.do_something("something", kw=", faif!")
'Doing something, faif!'
>>> delegator.do_anything()
Traceback (most recent call last):
...
AttributeError: 'Delegate' object has no attribute 'do_anything'
AttributeError: 'Delegate' object has no attribute 'do_anything'. Did you mean: 'do_something'?
"""

def __init__(self, delegate: Delegate) -> None:
Expand All @@ -47,8 +49,8 @@ class Delegate:
def __init__(self) -> None:
self.p1 = 123

def do_something(self, something: str) -> str:
return f"Doing {something}"
def do_something(self, something: str, kw=None) -> str:
return f"Doing {something}{kw or ''}"


if __name__ == "__main__":
Expand Down