from collections import defaultdict classdefaultdict(dict):
def__init__(self, default_factory=None, **kwargs):# known case of _collections.defaultdict.__init__ """ defaultdict(default_factory[, ...]) --> dict with default factory The default factory is called without arguments to produce a new value when a key is not present, in __getitem__ only. A defaultdict compares equal to a dict with the same items. All remaining arguments are treated the same as if they were passed to the dict constructor, including keyword arguments. # (copied from class doc) """ pass
def__missing__(self, key):# real signature unknown; restored from __doc__ """ __missing__(key) # Called by __getitem__ for missing key; pseudo-code: if self.default_factory is None: raise KeyError((key,)) self[key] = value = self.default_factory() return value """ pass
default_factory = property(lambda self: object(), lambda self, v: None, lambda self: None) # default """Factory for default value called by __missing__()."""