diff -r 20bb8babc505 Lib/functools.py --- a/Lib/functools.py Wed Nov 30 12:10:54 2016 +0100 +++ b/Lib/functools.py Thu Dec 01 16:05:51 2016 +0200 @@ -400,7 +400,7 @@ class partialmethod(object): ### LRU Cache function decorator ################################################################################ -_CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"]) +from functools_CacheInfo import CacheInfo as _CacheInfo class _HashedSeq(list): """ This class guarantees that hash() will be called no more than once diff -r 20bb8babc505 Lib/functools_CacheInfo.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/functools_CacheInfo.py Thu Dec 01 16:05:51 2016 +0200 @@ -0,0 +1,53 @@ +from builtins import property as _property, tuple as _tuple +from operator import itemgetter as _itemgetter +from collections import OrderedDict + +class CacheInfo(tuple): + 'CacheInfo(hits, misses, maxsize, currsize)' + + __slots__ = () + + _fields = ('hits', 'misses', 'maxsize', 'currsize') + + def __new__(_cls, hits, misses, maxsize, currsize): + 'Create new instance of CacheInfo(hits, misses, maxsize, currsize)' + return _tuple.__new__(_cls, (hits, misses, maxsize, currsize)) + + @classmethod + def _make(cls, iterable, new=tuple.__new__, len=len): + 'Make a new CacheInfo object from a sequence or iterable' + result = new(cls, iterable) + if len(result) != 4: + raise TypeError('Expected 4 arguments, got %d' % len(result)) + return result + + def _replace(_self, **kwds): + 'Return a new CacheInfo object replacing specified fields with new values' + result = _self._make(map(kwds.pop, ('hits', 'misses', 'maxsize', 'currsize'), _self)) + if kwds: + raise ValueError('Got unexpected field names: %r' % list(kwds)) + return result + + def __repr__(self): + 'Return a nicely formatted representation string' + return self.__class__.__name__ + '(hits=%r, misses=%r, maxsize=%r, currsize=%r)' % self + + def _asdict(self): + 'Return a new OrderedDict which maps field names to their values.' + return OrderedDict(zip(self._fields, self)) + + def __getnewargs__(self): + 'Return self as a plain tuple. Used by copy and pickle.' + return tuple(self) + + hits = _property(_itemgetter(0), doc='Alias for field number 0') + + misses = _property(_itemgetter(1), doc='Alias for field number 1') + + maxsize = _property(_itemgetter(2), doc='Alias for field number 2') + + currsize = _property(_itemgetter(3), doc='Alias for field number 3') + + +CacheInfo.__module__ = 'functools' +CacheInfo._source = "from builtins import property as _property, tuple as _tuple\nfrom operator import itemgetter as _itemgetter\nfrom collections import OrderedDict\n\nclass CacheInfo(tuple):\n 'CacheInfo(hits, misses, maxsize, currsize)'\n\n __slots__ = ()\n\n _fields = ('hits', 'misses', 'maxsize', 'currsize')\n\n def __new__(_cls, hits, misses, maxsize, currsize):\n 'Create new instance of CacheInfo(hits, misses, maxsize, currsize)'\n return _tuple.__new__(_cls, (hits, misses, maxsize, currsize))\n\n @classmethod\n def _make(cls, iterable, new=tuple.__new__, len=len):\n 'Make a new CacheInfo object from a sequence or iterable'\n result = new(cls, iterable)\n if len(result) != 4:\n raise TypeError('Expected 4 arguments, got %d' % len(result))\n return result\n\n def _replace(_self, **kwds):\n 'Return a new CacheInfo object replacing specified fields with new values'\n result = _self._make(map(kwds.pop, ('hits', 'misses', 'maxsize', 'currsize'), _self))\n if kwds:\n raise ValueError('Got unexpected field names: %r' % list(kwds))\n return result\n\n def __repr__(self):\n 'Return a nicely formatted representation string'\n return self.__class__.__name__ + '(hits=%r, misses=%r, maxsize=%r, currsize=%r)' % self\n\n def _asdict(self):\n 'Return a new OrderedDict which maps field names to their values.'\n return OrderedDict(zip(self._fields, self))\n\n def __getnewargs__(self):\n 'Return self as a plain tuple. Used by copy and pickle.'\n return tuple(self)\n\n hits = _property(_itemgetter(0), doc='Alias for field number 0')\n\n misses = _property(_itemgetter(1), doc='Alias for field number 1')\n\n maxsize = _property(_itemgetter(2), doc='Alias for field number 2')\n\n currsize = _property(_itemgetter(3), doc='Alias for field number 3')\n\n" diff -r 20bb8babc505 Makefile.pre.in --- a/Makefile.pre.in Wed Nov 30 12:10:54 2016 +0100 +++ b/Makefile.pre.in Thu Dec 01 16:05:51 2016 +0200 @@ -471,7 +471,7 @@ DTRACE_DEPS = \ # Default target all: @DEF_MAKE_ALL_RULE@ -build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Programs/_testembed python-config +build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Programs/_testembed python-config $(srcdir)/Lib/functools_CacheInfo.py # Compile a binary with profile guided optimization. profile-opt: @@ -563,6 +563,15 @@ coverage-report: clinic: $(BUILDPYTHON) $(srcdir)/Modules/_blake2/blake2s_impl.c $(RUNSHARED) $(PYTHON_FOR_BUILD) ./Tools/clinic/clinic.py --make +$(srcdir)/Lib/functools_CacheInfo.py: $(BUILDPYTHON) $(srcdir)/Lib/collections/__init__.py + $(RUNSHARED) $(PYTHON_FOR_BUILD) -c '\ + from collections import namedtuple;\ + CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"]);\ + print(CacheInfo._source);\ + print("CacheInfo.__module__ = %r" % "functools");\ + print("CacheInfo._source = %r" % CacheInfo._source);\ + ' >$(srcdir)/Lib/functools_CacheInfo.py + # Build the interpreter $(BUILDPYTHON): Programs/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY) $(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)