diff -r c642c597d05c Lib/collections/__init__.py --- a/Lib/collections/__init__.py Fri Dec 02 23:15:42 2016 +0200 +++ b/Lib/collections/__init__.py Sat Dec 03 19:04:03 2016 +0900 @@ -301,13 +301,13 @@ ### namedtuple ################################################################################ _class_template = """\ from builtins import property as _property, tuple as _tuple from operator import itemgetter as _itemgetter -from collections import OrderedDict +from collections import OrderedDict as _OrderedDict class {typename}(tuple): '{typename}({arg_list})' __slots__ = () @@ -335,13 +335,13 @@ def __repr__(self): 'Return a nicely formatted representation string' return self.__class__.__name__ + '({repr_fmt})' % self def _asdict(self): 'Return a new OrderedDict which maps field names to their values.' - return OrderedDict(zip(self._fields, self)) + return _OrderedDict(zip(self._fields, self)) def __getnewargs__(self): 'Return self as a plain tuple. Used by copy and pickle.' return tuple(self) {field_defs} diff -r c642c597d05c Lib/functools.py --- a/Lib/functools.py Fri Dec 02 23:15:42 2016 +0200 +++ b/Lib/functools.py Sat Dec 03 19:04:03 2016 +0900 @@ -15,13 +15,12 @@ try: from _functools import reduce except ImportError: pass from abc import get_cache_token -from collections import namedtuple from types import MappingProxyType from weakref import WeakKeyDictionary from reprlib import recursive_repr try: from _thread import RLock except ImportError: @@ -397,13 +396,78 @@ ################################################################################ ### LRU Cache function decorator ################################################################################ -_CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"]) +# Building namedtuple uses eval(). It's slower than normal class definition and +# .pyc file can't speedup it. +# Since functools is very common stdlib, we use code generation to optimize +# startup time of applications relying this module. + +#/*[python input] +#from collections import namedtuple +#CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"]) +#print(CacheInfo._source) +#[python start generated code]*/ +from builtins import property as _property, tuple as _tuple +from operator import itemgetter as _itemgetter +from collections import OrderedDict as _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') + + +#/*[python end generated code: output=0ed8ce9e3e1b7598 input=20f8f330d7ead40b]*/ + +_CacheInfo = CacheInfo +del CacheInfo + class _HashedSeq(list): """ This class guarantees that hash() will be called no more than once per element. This is important because the lru_cache() will hash the key multiple times on a cache miss. diff -r c642c597d05c Makefile.pre.in --- a/Makefile.pre.in Fri Dec 02 23:15:42 2016 +0200 +++ b/Makefile.pre.in Sat Dec 03 19:04:03 2016 +0900 @@ -554,17 +554,22 @@ $(MAKE) coverage @ # run tests, ignore failures $(TESTRUNNER) $(TESTOPTS) || true @ # build lcov report $(MAKE) coverage-lcov +# Python scripts using "Argument Clinic" +CLINIC_PY_FILES= \ + $(srcdir)/Lib/functools.py + # Run "Argument Clinic" over all source files # (depends on python having already been built) .PHONY=clinic -clinic: $(BUILDPYTHON) $(srcdir)/Modules/_blake2/blake2s_impl.c +clinic: $(BUILDPYTHON) $(srcdir)/Modules/_blake2/blake2s_impl.c $(CLINIC_PY_FILES) $(RUNSHARED) $(PYTHON_FOR_BUILD) ./Tools/clinic/clinic.py --make + $(RUNSHARED) $(PYTHON_FOR_BUILD) ./Tools/clinic/clinic.py $(CLINIC_PY_FILES) # Build the interpreter $(BUILDPYTHON): Programs/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY) $(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST) platform: $(BUILDPYTHON) pybuilddir.txt diff -r c642c597d05c Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py Fri Dec 02 23:15:42 2016 +0200 +++ b/Tools/clinic/clinic.py Sat Dec 03 19:04:03 2016 +0900 @@ -378,13 +378,12 @@ stop_line = "" checksum_line = "" def __init__(self, filename): pass - @abc.abstractmethod def render(self, clinic, signatures): pass def parse_line(self, line): pass @@ -1492,13 +1491,13 @@ write("\n") body_prefix = self.language.body_prefix.format(dsl_name=dsl_name) if not body_prefix: write(input) else: - for line in input.split('\n'): + for line in input.splitlines(): write(body_prefix) write(line) write("\n") write(self.language.stop_line.format(dsl_name=dsl_name)) write("\n")