MCPcopy Create free account
hub / github.com/dabeaz/python-cookbook / __new__

Method __new__

src/8/creating_cached_instances/example3.py:7–13  ·  view source on GitHub ↗
(cls, name)

Source from the content-addressed store, hash-verified

5class Spam:
6 _spam_cache = weakref.WeakValueDictionary()
7 def __new__(cls, name):
8 if name in cls._spam_cache:
9 return cls._spam_cache[name]
10 else:
11 self = super().__new__(cls)
12 cls._spam_cache[name] = self
13 return self
14
15 def __init__(self, name):
16 print('Initializing Spam')

Callers 4

unserialize_objectFunction · 0.45
todayMethod · 0.45
example.pyFile · 0.45
todayMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected