Hello community, here is the log from the commit of package python-cachetools for openSUSE:Factory checked in at 2017-06-09 15:57:49 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-cachetools (Old) and /work/SRC/openSUSE:Factory/.python-cachetools.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-cachetools" Fri Jun 9 15:57:49 2017 rev:3 rq:502431 version:2.0.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-cachetools/python-cachetools.changes 2016-09-01 14:03:09.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.python-cachetools.new/python-cachetools.changes 2017-06-09 15:57:49.548125899 +0200 @@ -1,0 +2,9 @@ +Thu Jun 1 21:04:54 UTC 2017 - [email protected] + +- update to 2.0.0: + - Drop Python 3.2 support (breaking change). + - Drop support for deprecated features (breaking change). + - Move key functions to separate package (breaking change). + - Accept non-integer ``maxsize`` in ``Cache.__repr__()``. + +------------------------------------------------------------------- Old: ---- cachetools-1.1.6.tar.gz New: ---- cachetools-2.0.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-cachetools.spec ++++++ --- /var/tmp/diff_new_pack.mwox50/_old 2017-06-09 15:57:50.100048000 +0200 +++ /var/tmp/diff_new_pack.mwox50/_new 2017-06-09 15:57:50.104047436 +0200 @@ -1,7 +1,7 @@ # # spec file for package python-cachetools # -# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,7 +17,7 @@ Name: python-cachetools -Version: 1.1.6 +Version: 2.0.0 Release: 0 Summary: Extensible memoizing collections and decorators License: MIT ++++++ cachetools-1.1.6.tar.gz -> cachetools-2.0.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/CHANGES.rst new/cachetools-2.0.0/CHANGES.rst --- old/cachetools-1.1.6/CHANGES.rst 2016-04-01 12:06:33.000000000 +0200 +++ new/cachetools-2.0.0/CHANGES.rst 2016-10-03 14:09:18.000000000 +0200 @@ -1,3 +1,15 @@ +v2.0.0 (2016-10-03) +------------------- + +- Drop Python 3.2 support (breaking change). + +- Drop support for deprecated features (breaking change). + +- Move key functions to separate package (breaking change). + +- Accept non-integer ``maxsize`` in ``Cache.__repr__()``. + + v1.1.6 (2016-04-01) ------------------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/LICENSE new/cachetools-2.0.0/LICENSE --- old/cachetools-1.1.6/LICENSE 2015-08-27 08:13:42.000000000 +0200 +++ new/cachetools-2.0.0/LICENSE 2016-04-22 15:03:41.000000000 +0200 @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014, 2015 Thomas Kemmer +Copyright (c) 2014-2016 Thomas Kemmer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/PKG-INFO new/cachetools-2.0.0/PKG-INFO --- old/cachetools-1.1.6/PKG-INFO 2016-04-01 12:07:29.000000000 +0200 +++ new/cachetools-2.0.0/PKG-INFO 2016-10-03 14:10:22.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: cachetools -Version: 1.1.6 +Version: 2.0.0 Summary: Extensible memoizing collections and decorators Home-page: https://github.com/tkem/cachetools Author: Thomas Kemmer @@ -59,10 +59,6 @@ :target: https://pypi.python.org/pypi/cachetools/ :alt: Latest PyPI version - .. image:: http://img.shields.io/pypi/dm/cachetools.svg?style=flat - :target: https://pypi.python.org/pypi/cachetools/ - :alt: Number of PyPI downloads - .. image:: http://img.shields.io/travis/tkem/cachetools/master.svg?style=flat :target: https://travis-ci.org/tkem/cachetools/ :alt: Travis CI build status @@ -96,7 +92,7 @@ .. _Change Log: https://github.com/tkem/cachetools/blob/master/CHANGES.rst .. _MIT License: http://raw.github.com/tkem/cachetools/master/LICENSE -Keywords: c,a,c,h,e, ,c,a,c,h,i,n,g, ,m,e,m,o,i,z,e, ,m,e,m,o,i,z,i,n,g, ,m,e,m,o,i,z,a,t,i,o,n, ,L,R,U, ,L,F,U, ,T,T,L +Keywords: cache caching memoize memoizing memoization LRU LFU TTL Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Other Environment @@ -107,7 +103,6 @@ Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/README.rst new/cachetools-2.0.0/README.rst --- old/cachetools-1.1.6/README.rst 2016-04-01 12:06:33.000000000 +0200 +++ new/cachetools-2.0.0/README.rst 2016-10-03 14:09:18.000000000 +0200 @@ -51,10 +51,6 @@ :target: https://pypi.python.org/pypi/cachetools/ :alt: Latest PyPI version -.. image:: http://img.shields.io/pypi/dm/cachetools.svg?style=flat - :target: https://pypi.python.org/pypi/cachetools/ - :alt: Number of PyPI downloads - .. image:: http://img.shields.io/travis/tkem/cachetools/master.svg?style=flat :target: https://travis-ci.org/tkem/cachetools/ :alt: Travis CI build status diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/cachetools/__init__.py new/cachetools-2.0.0/cachetools/__init__.py --- old/cachetools-1.1.6/cachetools/__init__.py 2016-04-01 12:06:33.000000000 +0200 +++ new/cachetools-2.0.0/cachetools/__init__.py 2016-10-03 14:09:18.000000000 +0200 @@ -1,11 +1,11 @@ """Extensible memoizing collections and decorators.""" +from __future__ import absolute_import + import functools -import warnings +from . import keys from .cache import Cache -from .func import lfu_cache, lru_cache, rr_cache, ttl_cache -from .keys import hashkey, typedkey from .lfu import LFUCache from .lru import LRUCache from .rr import RRCache @@ -13,14 +13,10 @@ __all__ = ( 'Cache', 'LFUCache', 'LRUCache', 'RRCache', 'TTLCache', - 'cached', 'cachedmethod', 'hashkey', 'typedkey', - # make cachetools.func.* available for backwards compatibility - 'lfu_cache', 'lru_cache', 'rr_cache', 'ttl_cache', + 'cached', 'cachedmethod' ) -__version__ = '1.1.6' - -_default = [] # evaluates to False +__version__ = '2.0.0' if hasattr(functools.update_wrapper(lambda f: f(), lambda: 42), '__wrapped__'): _update_wrapper = functools.update_wrapper @@ -31,7 +27,7 @@ return wrapper -def cached(cache, key=hashkey, lock=None): +def cached(cache, key=keys.hashkey, lock=None): """Decorator to wrap a function with a memoizing callable that saves results in a cache. @@ -72,29 +68,18 @@ return decorator -def cachedmethod(cache, key=_default, lock=None, typed=_default): +def cachedmethod(cache, key=keys.hashkey, lock=None): """Decorator to wrap a class or instance method with a memoizing callable that saves results in a cache. """ - if key is not _default and not callable(key): - key, typed = _default, key - if typed is not _default: - warnings.warn("Passing 'typed' to cachedmethod() is deprecated, " - "use 'key=typedkey' instead", DeprecationWarning, 2) - def decorator(method): - # pass method to default key function for backwards compatibilty - if key is _default: - makekey = functools.partial(typedkey if typed else hashkey, method) - else: - makekey = key # custom key function always receive method args if lock is None: def wrapper(self, *args, **kwargs): c = cache(self) if c is None: return method(self, *args, **kwargs) - k = makekey(self, *args, **kwargs) + k = key(self, *args, **kwargs) try: return c[k] except KeyError: @@ -110,7 +95,7 @@ c = cache(self) if c is None: return method(self, *args, **kwargs) - k = makekey(self, *args, **kwargs) + k = key(self, *args, **kwargs) try: with lock(self): return c[k] @@ -123,13 +108,5 @@ except ValueError: pass # value too large return v - _update_wrapper(wrapper, method) - - # deprecated wrapper attribute - def getter(self): - warnings.warn('%s.cache is deprecated' % method.__name__, - DeprecationWarning, 2) - return cache(self) - wrapper.cache = getter - return wrapper + return _update_wrapper(wrapper, method) return decorator diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/cachetools/cache.py new/cachetools-2.0.0/cachetools/cache.py --- old/cachetools-1.1.6/cachetools/cache.py 2016-04-01 12:06:33.000000000 +0200 +++ new/cachetools-2.0.0/cachetools/cache.py 2016-10-03 14:09:18.000000000 +0200 @@ -1,3 +1,5 @@ +from __future__ import absolute_import + from .abc import DefaultMapping @@ -28,7 +30,7 @@ self.__maxsize = maxsize def __repr__(self): - return '%s(%r, maxsize=%d, currsize=%d)' % ( + return '%s(%r, maxsize=%r, currsize=%r)' % ( self.__class__.__name__, list(self.__data.items()), self.__maxsize, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/cachetools/func.py new/cachetools-2.0.0/cachetools/func.py --- old/cachetools-1.1.6/cachetools/func.py 2015-08-31 14:31:32.000000000 +0200 +++ new/cachetools-2.0.0/cachetools/func.py 2016-10-03 14:09:18.000000000 +0200 @@ -1,48 +1,35 @@ """`functools.lru_cache` compatible memoizing function decorators.""" +from __future__ import absolute_import + import collections import functools import random import time -import warnings try: from threading import RLock except ImportError: from dummy_threading import RLock -from .keys import hashkey, typedkey +from . import keys +from .lfu import LFUCache +from .lru import LRUCache +from .rr import RRCache +from .ttl import TTLCache __all__ = ('lfu_cache', 'lru_cache', 'rr_cache', 'ttl_cache') -class _NLock: - def __enter__(self): - pass - - def __exit__(self, *exc): - pass - _CacheInfo = collections.namedtuple('CacheInfo', [ 'hits', 'misses', 'maxsize', 'currsize' ]) -_marker = object() - - -def _deprecated(message, level=2): - warnings.warn('%s is deprecated' % message, DeprecationWarning, level) - -def _cache(cache, typed=False, context=_marker): +def _cache(cache, typed=False): def decorator(func): - key = typedkey if typed else hashkey - if context is _marker: - lock = RLock() - elif context is None: - lock = _NLock() - else: - lock = context() + key = keys.typedkey if typed else keys.hashkey + lock = RLock() stats = [0, 0] def cache_info(): @@ -77,57 +64,43 @@ return v functools.update_wrapper(wrapper, func) if not hasattr(wrapper, '__wrapped__'): - wrapper.__wrapped__ = func # Python < 3.2 + wrapper.__wrapped__ = func # Python 2.7 wrapper.cache_info = cache_info wrapper.cache_clear = cache_clear return wrapper return decorator -def lfu_cache(maxsize=128, typed=False, getsizeof=None, lock=_marker): +def lfu_cache(maxsize=128, typed=False): """Decorator to wrap a function with a memoizing callable that saves up to `maxsize` results based on a Least Frequently Used (LFU) algorithm. """ - from .lfu import LFUCache - if lock is not _marker: - _deprecated("Passing 'lock' to lfu_cache()", 3) - return _cache(LFUCache(maxsize, getsizeof), typed, lock) + return _cache(LFUCache(maxsize), typed) -def lru_cache(maxsize=128, typed=False, getsizeof=None, lock=_marker): +def lru_cache(maxsize=128, typed=False): """Decorator to wrap a function with a memoizing callable that saves up to `maxsize` results based on a Least Recently Used (LRU) algorithm. """ - from .lru import LRUCache - if lock is not _marker: - _deprecated("Passing 'lock' to lru_cache()", 3) - return _cache(LRUCache(maxsize, getsizeof), typed, lock) + return _cache(LRUCache(maxsize), typed) -def rr_cache(maxsize=128, choice=random.choice, typed=False, getsizeof=None, - lock=_marker): +def rr_cache(maxsize=128, choice=random.choice, typed=False): """Decorator to wrap a function with a memoizing callable that saves up to `maxsize` results based on a Random Replacement (RR) algorithm. """ - from .rr import RRCache - if lock is not _marker: - _deprecated("Passing 'lock' to rr_cache()", 3) - return _cache(RRCache(maxsize, choice, getsizeof), typed, lock) + return _cache(RRCache(maxsize, choice), typed) -def ttl_cache(maxsize=128, ttl=600, timer=time.time, typed=False, - getsizeof=None, lock=_marker): +def ttl_cache(maxsize=128, ttl=600, timer=time.time, typed=False): """Decorator to wrap a function with a memoizing callable that saves up to `maxsize` results based on a Least Recently Used (LRU) algorithm with a per-item time-to-live (TTL) value. """ - from .ttl import TTLCache - if lock is not _marker: - _deprecated("Passing 'lock' to ttl_cache()", 3) - return _cache(TTLCache(maxsize, ttl, timer, getsizeof), typed, lock) + return _cache(TTLCache(maxsize, ttl, timer), typed) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/cachetools/keys.py new/cachetools-2.0.0/cachetools/keys.py --- old/cachetools-1.1.6/cachetools/keys.py 2015-09-15 09:10:42.000000000 +0200 +++ new/cachetools-2.0.0/cachetools/keys.py 2016-10-03 14:09:18.000000000 +0200 @@ -1,3 +1,7 @@ +"""Key functions for memoizing decorators.""" + +from __future__ import absolute_import + __all__ = ('hashkey', 'typedkey') diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/cachetools/lfu.py new/cachetools-2.0.0/cachetools/lfu.py --- old/cachetools-1.1.6/cachetools/lfu.py 2016-04-01 12:06:33.000000000 +0200 +++ new/cachetools-2.0.0/cachetools/lfu.py 2016-10-03 14:09:18.000000000 +0200 @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import collections from .cache import Cache diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/cachetools/lru.py new/cachetools-2.0.0/cachetools/lru.py --- old/cachetools-1.1.6/cachetools/lru.py 2016-04-01 12:06:33.000000000 +0200 +++ new/cachetools-2.0.0/cachetools/lru.py 2016-10-03 14:09:18.000000000 +0200 @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import collections from .cache import Cache diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/cachetools/rr.py new/cachetools-2.0.0/cachetools/rr.py --- old/cachetools-1.1.6/cachetools/rr.py 2016-04-01 12:06:33.000000000 +0200 +++ new/cachetools-2.0.0/cachetools/rr.py 2016-10-03 14:09:18.000000000 +0200 @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import random from .cache import Cache diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/cachetools/ttl.py new/cachetools-2.0.0/cachetools/ttl.py --- old/cachetools-1.1.6/cachetools/ttl.py 2016-04-01 12:06:33.000000000 +0200 +++ new/cachetools-2.0.0/cachetools/ttl.py 2016-10-03 14:09:18.000000000 +0200 @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import collections import time diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/cachetools.egg-info/PKG-INFO new/cachetools-2.0.0/cachetools.egg-info/PKG-INFO --- old/cachetools-1.1.6/cachetools.egg-info/PKG-INFO 2016-04-01 12:07:29.000000000 +0200 +++ new/cachetools-2.0.0/cachetools.egg-info/PKG-INFO 2016-10-03 14:10:21.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: cachetools -Version: 1.1.6 +Version: 2.0.0 Summary: Extensible memoizing collections and decorators Home-page: https://github.com/tkem/cachetools Author: Thomas Kemmer @@ -59,10 +59,6 @@ :target: https://pypi.python.org/pypi/cachetools/ :alt: Latest PyPI version - .. image:: http://img.shields.io/pypi/dm/cachetools.svg?style=flat - :target: https://pypi.python.org/pypi/cachetools/ - :alt: Number of PyPI downloads - .. image:: http://img.shields.io/travis/tkem/cachetools/master.svg?style=flat :target: https://travis-ci.org/tkem/cachetools/ :alt: Travis CI build status @@ -96,7 +92,7 @@ .. _Change Log: https://github.com/tkem/cachetools/blob/master/CHANGES.rst .. _MIT License: http://raw.github.com/tkem/cachetools/master/LICENSE -Keywords: c,a,c,h,e, ,c,a,c,h,i,n,g, ,m,e,m,o,i,z,e, ,m,e,m,o,i,z,i,n,g, ,m,e,m,o,i,z,a,t,i,o,n, ,L,R,U, ,L,F,U, ,T,T,L +Keywords: cache caching memoize memoizing memoization LRU LFU TTL Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Other Environment @@ -107,7 +103,6 @@ Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/docs/index.rst new/cachetools-2.0.0/docs/index.rst --- old/cachetools-1.1.6/docs/index.rst 2016-03-29 08:55:38.000000000 +0200 +++ new/cachetools-2.0.0/docs/index.rst 2016-10-03 14:09:18.000000000 +0200 @@ -21,20 +21,6 @@ implemented, and decorators for easily memoizing function and method calls are provided, too. -.. note:: - - Several features are now marked as deprecated and will be removed - in the next major release, :mod:`cachetools` version 2.0. If you - happen to rely on any of these features, it is highly recommended - to specify your module dependencies accordingly, for example - ``cachetools ~= 1.1`` when using :mod:`setuptools`. - -.. versionchanged:: 1.1 - - Moved :func:`functools.lru_cache` compatible decorators to the - :mod:`cachetools.func` module. For backwards compatibility, they - continue to be visible in this module as well. - Cache implementations ------------------------------------------------------------------------ @@ -149,7 +135,7 @@ expired by the current value returned by :attr:`timer`. -Decorators +Memoizing decorators ------------------------------------------------------------------------ The :mod:`cachetools` module provides decorators for memoizing @@ -165,7 +151,7 @@ for i in range(100): print('fib(%d) = %d' % (i, fib(i))) -.. decorator:: cached(cache, key=hashkey, lock=None) +.. decorator:: cached(cache, key=cachetools.keys.hashkey, lock=None) Decorator to wrap a function with a memoizing callable that saves results in a cache. @@ -181,7 +167,7 @@ positional and keyword arguments as the wrapped function itself, and which has to return a suitable cache key. Since caches are mappings, the object returned by `key` must be hashable. The - default is to call :func:`hashkey`. + default is to call :func:`cachetools.keys.hashkey`. If `lock` is not :const:`None`, it must specify an object implementing the `context manager`_ protocol. Any access to the @@ -241,9 +227,7 @@ print(fac(42)) print(cache) - .. versionadded:: 1.1 - -.. decorator:: cachedmethod(cache, key=hashkey, lock=None, typed=False) +.. decorator:: cachedmethod(cache, key=cachetools.keys.hashkey, lock=None) Decorator to wrap a class or instance method with a memoizing callable that saves results in a (possibly shared) cache. @@ -261,11 +245,6 @@ is the user's responsibility to handle concurrent calls to the underlying wrapped method in a multithreaded environment. - If `key` or the optional `typed` keyword argument are set to - :const:`True`, the :func:`typedkey` function is used for generating - hash keys. This has been deprecated in favor of specifying - ``key=typedkey`` explicitly. - One advantage of :func:`cachedmethod` over the :func:`cached` function decorator is that cache properties such as `maxsize` can be set at runtime:: @@ -290,51 +269,20 @@ peps = CachedPEPs(cachesize=10) print("PEP #1: %s" % peps.get(1)) - For backwards compatibility, the default key function used by - :func:`cachedmethod` will generate distinct keys for different - methods to ease using a shared cache with multiple methods. This - has been deprecated, and relying on this feature is strongly - discouraged. When using a shared cache, distinct key functions - should be used, as with the :func:`cached` decorator. - - .. versionadded:: 1.1 - - The optional `key` and `lock` parameters. - - .. versionchanged:: 1.1 - - The :attr:`__wrapped__` attribute is now set when running Python - 2.7, too. - - .. deprecated:: 1.1 - - The `typed` argument. Use ``key=typedkey`` instead. - - .. deprecated:: 1.1 - - When using a shared cached for multiple methods, distinct key - function should be used. - - .. deprecated:: 1.1 - - The wrapper function's :attr:`cache` attribute. Use the - original function passed as the decorator's `cache` argument to - access the cache object. +:mod:`cachetools.keys` --- Key functions for memoizing decorators +============================================================================ -Key functions ------------------------------------------------------------------------- +.. module:: cachetools.keys -The following functions can be used as key functions with the -:func:`cached` and :func:`cachedmethod` decorators: +This module provides several functions that can be used as key +functions with the :func:`cached` and :func:`cachedmethod` decorators: .. autofunction:: hashkey This function returns a :class:`tuple` instance suitable as a cache key, provided the positional and keywords arguments are hashable. - .. versionadded:: 1.1 - .. autofunction:: typedkey This function is similar to :func:`hashkey`, but arguments of @@ -342,8 +290,6 @@ ``typedkey(3)`` and ``typedkey(3.0)`` will return different results. - .. versionadded:: 1.1 - These functions can also be helpful when implementing custom key functions for handling some non-hashable arguments. For example, calling the following function with a dictionary as its `env` argument @@ -381,77 +327,40 @@ :func:`functools.lru_cache`, setting `maxsize` to :const:`None` is not supported. +If the optional argument `typed` is set to :const:`True`, function +arguments of different types will be cached separately. For example, +``f(3)`` and ``f(3.0)`` will be treated as distinct calls with +distinct results. + The wrapped function is instrumented with :func:`cache_info` and :func:`cache_clear` functions to provide information about cache performance and clear the cache. See the :func:`functools.lru_cache` documentation for details. -In addition to `maxsize`, all decorators accept the following -optional keyword arguments: - -- `typed`, if is set to :const:`True`, will cause function arguments - of different types to be cached separately. For example, ``f(3)`` - and ``f(3.0)`` will be treated as distinct calls with distinct - results. - -- `getsizeof` specifies a function of one argument that will be - applied to each cache value to determine its size. The default - value is :const:`None`, which will assign each item an equal size of - :const:`1`. This has been deprecated in favor of the new - :func:`cachetools.cached` decorator, which allows passing fully - customized cache objects. - -- `lock` specifies a function of zero arguments that returns a - `context manager`_ to lock the cache when necessary. If not - specified, :class:`threading.RLock` will be used to synchronize - access from multiple threads. The use of `lock` is discouraged, and - the `lock` argument has been deprecated. - -.. versionadded:: 1.1 - - Formerly, the decorators provided by :mod:`cachetools.func` were - part of the :mod:`cachetools` module. - -.. decorator:: lfu_cache(maxsize=128, typed=False, getsizeof=None, lock=threading.RLock) +.. decorator:: lfu_cache(maxsize=128, typed=False) Decorator that wraps a function with a memoizing callable that saves up to `maxsize` results based on a Least Frequently Used (LFU) algorithm. - .. deprecated:: 1.1 - - The `getsizeof` and `lock` arguments. - -.. decorator:: lru_cache(maxsize=128, typed=False, getsizeof=None, lock=threading.RLock) +.. decorator:: lru_cache(maxsize=128, typed=False) Decorator that wraps a function with a memoizing callable that saves up to `maxsize` results based on a Least Recently Used (LRU) algorithm. - .. deprecated:: 1.1 - - The `getsizeof` and `lock` arguments. - -.. decorator:: rr_cache(maxsize=128, choice=random.choice, typed=False, getsizeof=None, lock=threading.RLock) +.. decorator:: rr_cache(maxsize=128, choice=random.choice, typed=False) Decorator that wraps a function with a memoizing callable that saves up to `maxsize` results based on a Random Replacement (RR) algorithm. - .. deprecated:: 1.1 - - The `getsizeof` and `lock` arguments. - -.. decorator:: ttl_cache(maxsize=128, ttl=600, timer=time.time, typed=False, getsizeof=None, lock=threading.RLock) +.. decorator:: ttl_cache(maxsize=128, ttl=600, timer=time.time, typed=False) Decorator to wrap a function with a memoizing callable that saves up to `maxsize` results based on a Least Recently Used (LRU) algorithm with a per-item time-to-live (TTL) value. - .. deprecated:: 1.1 - - The `getsizeof` and `lock` arguments. - .. _@lru_cache: http://docs.python.org/3/library/functools.html#functools.lru_cache .. _cache algorithm: http://en.wikipedia.org/wiki/Cache_algorithms diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/setup.py new/cachetools-2.0.0/setup.py --- old/cachetools-1.1.6/setup.py 2016-04-01 12:06:33.000000000 +0200 +++ new/cachetools-2.0.0/setup.py 2016-10-03 14:09:18.000000000 +0200 @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from setuptools import find_packages, setup @@ -30,7 +28,6 @@ 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/tests/test_func.py new/cachetools-2.0.0/tests/test_func.py --- old/cachetools-1.1.6/tests/test_func.py 2015-08-31 14:31:32.000000000 +0200 +++ new/cachetools-2.0.0/tests/test_func.py 2016-10-03 14:09:18.000000000 +0200 @@ -1,5 +1,4 @@ import unittest -import warnings import cachetools.func @@ -55,52 +54,6 @@ self.assertEqual(cached(1.0), 1.0) self.assertEqual(cached.cache_info(), (2, 2, 2, 2)) - def test_decorator_lock(self): - class Lock(object): - count = 0 - - def __enter__(self): - Lock.count += 1 - - def __exit__(self, *exc): - pass - - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') - cached = self.decorator(maxsize=2, lock=Lock)(lambda n: n) - self.assertEqual(len(w), 1) - self.assertIs(w[0].category, DeprecationWarning) - - self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) - self.assertEqual(Lock.count, 1) - self.assertEqual(cached(1), 1) - self.assertEqual(Lock.count, 3) - self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) - self.assertEqual(Lock.count, 4) - self.assertEqual(cached(1), 1) - self.assertEqual(Lock.count, 5) - self.assertEqual(cached.cache_info(), (1, 1, 2, 1)) - self.assertEqual(Lock.count, 6) - self.assertEqual(cached(1.0), 1.0) - self.assertEqual(Lock.count, 7) - self.assertEqual(cached.cache_info(), (2, 1, 2, 1)) - self.assertEqual(Lock.count, 8) - - def test_decorator_nolock(self): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter('always') - cached = self.decorator(maxsize=2, lock=None)(lambda n: n) - self.assertEqual(len(w), 1) - self.assertIs(w[0].category, DeprecationWarning) - - self.assertEqual(cached.cache_info(), (0, 0, 2, 0)) - self.assertEqual(cached(1), 1) - self.assertEqual(cached.cache_info(), (0, 1, 2, 1)) - self.assertEqual(cached(1), 1) - self.assertEqual(cached.cache_info(), (1, 1, 2, 1)) - self.assertEqual(cached(1.0), 1.0) - self.assertEqual(cached.cache_info(), (2, 1, 2, 1)) - class LFUDecoratorTest(unittest.TestCase, DecoratorTestMixin): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/tests/test_keys.py new/cachetools-2.0.0/tests/test_keys.py --- old/cachetools-1.1.6/tests/test_keys.py 2015-09-15 09:10:42.000000000 +0200 +++ new/cachetools-2.0.0/tests/test_keys.py 2016-10-03 14:09:18.000000000 +0200 @@ -1,11 +1,11 @@ import unittest -import cachetools +import cachetools.keys class CacheKeysTest(unittest.TestCase): - def test_hashkey(self, key=cachetools.hashkey): + def test_hashkey(self, key=cachetools.keys.hashkey): self.assertEqual(key(), key()) self.assertEqual(hash(key()), hash(key())) self.assertEqual(key(1, 2, 3), key(1, 2, 3)) @@ -22,7 +22,7 @@ self.assertEqual(key(1, 2, 3), key(1.0, 2.0, 3.0)) self.assertEqual(hash(key(1, 2, 3)), hash(key(1.0, 2.0, 3.0))) - def test_typedkey(self, key=cachetools.typedkey): + def test_typedkey(self, key=cachetools.keys.typedkey): self.assertEqual(key(), key()) self.assertEqual(hash(key()), hash(key())) self.assertEqual(key(1, 2, 3), key(1, 2, 3)) @@ -38,7 +38,7 @@ # typed keys compare unequal self.assertNotEqual(key(1, 2, 3), key(1.0, 2.0, 3.0)) - def test_addkeys(self, key=cachetools.hashkey): + def test_addkeys(self, key=cachetools.keys.hashkey): self.assertIsInstance(key(), tuple) self.assertIsInstance(key(1, 2, 3) + key(4, 5, 6), type(key())) self.assertIsInstance(key(1, 2, 3) + (4, 5, 6), type(key())) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/tests/test_method.py new/cachetools-2.0.0/tests/test_method.py --- old/cachetools-1.1.6/tests/test_method.py 2015-09-15 09:10:42.000000000 +0200 +++ new/cachetools-2.0.0/tests/test_method.py 2016-10-03 14:09:18.000000000 +0200 @@ -1,8 +1,7 @@ import operator import unittest -import warnings -from cachetools import LRUCache, cachedmethod, typedkey +from cachetools import LRUCache, cachedmethod, keys class Cached(object): @@ -17,7 +16,7 @@ self.count += 1 return count - @cachedmethod(operator.attrgetter('cache'), key=typedkey) + @cachedmethod(operator.attrgetter('cache'), key=keys.typedkey) def get_typed(self, value): count = self.count self.count += 1 @@ -45,7 +44,6 @@ def test_dict(self): cached = Cached({}) - self.assertEqual(cached.cache, cached.get.cache(cached)) self.assertEqual(cached.get(0), 0) self.assertEqual(cached.get(1), 1) @@ -58,7 +56,6 @@ def test_typed_dict(self): cached = Cached(LRUCache(maxsize=2)) - self.assertEqual(cached.cache, cached.get_typed.cache(cached)) self.assertEqual(cached.get_typed(0), 0) self.assertEqual(cached.get_typed(1), 1) @@ -70,7 +67,6 @@ def test_lru(self): cached = Cached(LRUCache(maxsize=2)) - self.assertEqual(cached.cache, cached.get.cache(cached)) self.assertEqual(cached.get(0), 0) self.assertEqual(cached.get(1), 1) @@ -83,7 +79,6 @@ def test_typed_lru(self): cached = Cached(LRUCache(maxsize=2)) - self.assertEqual(cached.cache, cached.get_typed.cache(cached)) self.assertEqual(cached.get_typed(0), 0) self.assertEqual(cached.get_typed(1), 1) @@ -95,7 +90,6 @@ def test_nospace(self): cached = Cached(LRUCache(maxsize=0)) - self.assertEqual(cached.cache, cached.get.cache(cached)) self.assertEqual(cached.get(0), 0) self.assertEqual(cached.get(1), 1) @@ -105,7 +99,6 @@ def test_nocache(self): cached = Cached(None) - self.assertEqual(None, cached.get.cache(cached)) self.assertEqual(cached.get(0), 0) self.assertEqual(cached.get(1), 1) @@ -124,7 +117,6 @@ return Int(fractions.Fraction.__add__(self, other)) cached = Cached(weakref.WeakValueDictionary(), count=Int(0)) - self.assertEqual(cached.cache, cached.get.cache(cached)) self.assertEqual(cached.get(0), 0) self.assertEqual(cached.get(0), 1) @@ -144,7 +136,6 @@ def test_locked_dict(self): cached = Locked({}) - self.assertEqual(cached.cache, cached.get.cache(cached)) self.assertEqual(cached.get(0), 1) self.assertEqual(cached.get(1), 3) @@ -154,7 +145,6 @@ def test_locked_nocache(self): cached = Locked(None) - self.assertEqual(None, cached.get.cache(cached)) self.assertEqual(cached.get(0), 0) self.assertEqual(cached.get(1), 0) @@ -164,28 +154,9 @@ def test_locked_nospace(self): cached = Locked(LRUCache(maxsize=0)) - self.assertEqual(cached.cache, cached.get.cache(cached)) self.assertEqual(cached.get(0), 1) self.assertEqual(cached.get(1), 3) self.assertEqual(cached.get(1), 5) self.assertEqual(cached.get(1.0), 7) self.assertEqual(cached.get(1.0), 9) - - def test_typed_deprecated(self): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always") - cachedmethod(lambda self: None, None)(lambda self: None) - self.assertIs(w[-1].category, DeprecationWarning) - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always") - cachedmethod(lambda self: None, False)(lambda self: None) - self.assertIs(w[-1].category, DeprecationWarning) - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always") - cachedmethod(lambda self: None, True)(lambda self: None) - self.assertIs(w[-1].category, DeprecationWarning) - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always") - cachedmethod(lambda self: None, typed=None)(lambda self: None) - self.assertIs(w[-1].category, DeprecationWarning) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/tests/test_wrapper.py new/cachetools-2.0.0/tests/test_wrapper.py --- old/cachetools-1.1.6/tests/test_wrapper.py 2015-09-15 09:10:42.000000000 +0200 +++ new/cachetools-2.0.0/tests/test_wrapper.py 2016-10-03 14:09:18.000000000 +0200 @@ -1,6 +1,7 @@ import unittest import cachetools +import cachetools.keys class DecoratorTestMixin(object): @@ -24,15 +25,15 @@ self.assertEqual(wrapper(0), 0) self.assertEqual(len(cache), 1) - self.assertIn(cachetools.hashkey(0), cache) - self.assertNotIn(cachetools.hashkey(1), cache) - self.assertNotIn(cachetools.hashkey(1.0), cache) + self.assertIn(cachetools.keys.hashkey(0), cache) + self.assertNotIn(cachetools.keys.hashkey(1), cache) + self.assertNotIn(cachetools.keys.hashkey(1.0), cache) self.assertEqual(wrapper(1), 1) self.assertEqual(len(cache), 2) - self.assertIn(cachetools.hashkey(0), cache) - self.assertIn(cachetools.hashkey(1), cache) - self.assertIn(cachetools.hashkey(1.0), cache) + self.assertIn(cachetools.keys.hashkey(0), cache) + self.assertIn(cachetools.keys.hashkey(1), cache) + self.assertIn(cachetools.keys.hashkey(1.0), cache) self.assertEqual(wrapper(1), 1) self.assertEqual(len(cache), 2) @@ -45,37 +46,32 @@ def test_decorator_typed(self): cache = self.cache(3) - - def typedkey(*args, **kwargs): - key = cachetools.hashkey(*args, **kwargs) - key += tuple(type(v) for v in args) - key += tuple(type(v) for _, v in sorted(kwargs.items())) - return key - wrapper = cachetools.cached(cache, key=typedkey)(self.func) + key = cachetools.keys.typedkey + wrapper = cachetools.cached(cache, key=key)(self.func) self.assertEqual(len(cache), 0) self.assertEqual(wrapper.__wrapped__, self.func) self.assertEqual(wrapper(0), 0) self.assertEqual(len(cache), 1) - self.assertIn(typedkey(0), cache) - self.assertNotIn(typedkey(1), cache) - self.assertNotIn(typedkey(1.0), cache) + self.assertIn(cachetools.keys.typedkey(0), cache) + self.assertNotIn(cachetools.keys.typedkey(1), cache) + self.assertNotIn(cachetools.keys.typedkey(1.0), cache) self.assertEqual(wrapper(1), 1) self.assertEqual(len(cache), 2) - self.assertIn(typedkey(0), cache) - self.assertIn(typedkey(1), cache) - self.assertNotIn(typedkey(1.0), cache) + self.assertIn(cachetools.keys.typedkey(0), cache) + self.assertIn(cachetools.keys.typedkey(1), cache) + self.assertNotIn(cachetools.keys.typedkey(1.0), cache) self.assertEqual(wrapper(1), 1) self.assertEqual(len(cache), 2) self.assertEqual(wrapper(1.0), 2) self.assertEqual(len(cache), 3) - self.assertIn(typedkey(0), cache) - self.assertIn(typedkey(1), cache) - self.assertIn(typedkey(1.0), cache) + self.assertIn(cachetools.keys.typedkey(0), cache) + self.assertIn(cachetools.keys.typedkey(1), cache) + self.assertIn(cachetools.keys.typedkey(1.0), cache) self.assertEqual(wrapper(1.0), 2) self.assertEqual(len(cache), 3) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/cachetools-1.1.6/tox.ini new/cachetools-2.0.0/tox.ini --- old/cachetools-1.1.6/tox.ini 2016-04-01 12:06:33.000000000 +0200 +++ new/cachetools-2.0.0/tox.ini 2016-10-03 14:09:18.000000000 +0200 @@ -2,9 +2,8 @@ envlist = check-manifest,docs,flake8,py [testenv] -# coverage 4.0 drops Python 3.2 compatibility deps = - coverage<4 + coverage pytest pytest-cov commands =
