Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
_collections.py35 linesDownload Raw Back to importlib_metadata
1import collections2import typing3 4 5# from jaraco.collections 3.36class FreezableDefaultDict(collections.defaultdict):7    """8    Often it is desirable to prevent the mutation of9    a default dict after its initial construction, such10    as to prevent mutation during iteration.11 12    >>> dd = FreezableDefaultDict(list)13    >>> dd[0].append('1')14    >>> dd.freeze()15    >>> dd[1]16    []17    >>> len(dd)18    119    """20 21    def __missing__(self, key):22        return getattr(self, '_frozen', super().__missing__)(key)23 24    def freeze(self):25        self._frozen = lambda key: self.default_factory()26 27 28class Pair(typing.NamedTuple):29    name: str30    value: str31 32    @classmethod33    def parse(cls, text):34        return cls(*map(str.strip, text.split("=", 1)))35 
codekingpro/portable-devtools · Team Ai