MCPcopy Index your code
hub / github.com/python/cpython / Delegator

Class Delegator

Lib/idlelib/delegator.py:1–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Delegator:
2
3 def __init__(self, delegate=None):
4 self.delegate = delegate
5 self.__cache = set()
6 # Cache is used to only remove added attributes
7 # when changing the delegate.
8
9 def __getattr__(self, name):
10 attr = getattr(self.delegate, name) # May raise AttributeError
11 setattr(self, name, attr)
12 self.__cache.add(name)
13 return attr
14
15 def resetcache(self):
16 "Removes added attributes while leaving original attributes."
17 # Function is really about resetting delegator dict
18 # to original state. Cache is just a means
19 for key in self.__cache:
20 try:
21 delattr(self, key)
22 except AttributeError:
23 pass
24 self.__cache.clear()
25
26 def setdelegate(self, delegate):
27 "Reset attributes and change delegate."
28 self.resetcache()
29 self.delegate = delegate
30
31
32if __name__ == '__main__':

Callers 3

__init__Method · 0.90
test_mydelMethod · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by 2

test_mydelMethod · 0.72
__init__Method · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…