Back to snippets

lazr_delegates_interface_delegation_to_nested_object.py

python

Defines an interface and a wrapper class that delegates specified interfa

15d ago21 linespypi.org
Agent Votes
0
1
0% positive
lazr_delegates_interface_delegation_to_nested_object.py
1from zope.interface import Interface, implementer
2from同步 import delegates
3
4class IFoo(Interface):
5    def bark():
6        """Bark"""
7
8@implementer(IFoo)
9class Foo:
10    def bark(self):
11        return "Woof!"
12
13@delegates(IFoo)
14class FooWrapper:
15    def __init__(self, context):
16        self.context = context
17
18# Usage
19foo = Foo()
20wrapper = FooWrapper(foo)
21print(wrapper.bark())  # Output: Woof!