MCPcopy
hub / github.com/fluentpython/example-code-2e / __init__

Method __init__

03-dict-set/transformdict.py:33–48  ·  view source on GitHub ↗

Create a new TransformDict with the given *transform* function. *init_dict* and *kwargs* are optional initializers, as in the dict constructor.

(self, transform, init_dict=None, **kwargs)

Source from the content-addressed store, hash-verified

31 __slots__ = ('_transform', '_original', '_data')
32
33 def __init__(self, transform, init_dict=None, **kwargs):
34 """Create a new TransformDict with the given *transform* function.
35 *init_dict* and *kwargs* are optional initializers, as in the
36 dict constructor.
37 """
38 if not callable(transform):
39 raise TypeError(
40 f'expected a callable, got {transform.__class__!r}')
41 self._transform = transform
42 # transformed => original
43 self._original = {}
44 self._data = {}
45 if init_dict:
46 self.update(init_dict)
47 if kwargs:
48 self.update(kwargs)
49
50 def getitem(self, key):
51 """D.getitem(key) -> (stored key, value)"""

Callers

nothing calls this directly

Calls 1

updateMethod · 0.45

Tested by

no test coverage detected