Expand standard functools to methods
Project description
Expand functools features to methods, classmethods, staticmethods and even for (unofficial) hybrid methods.
For now, methodtools only provides methodtools.lru_cache.
Use methodtools module instead of functools module. Than it will work as you expected.
from methodtools import lru_cache
class A(object):
# cached method. the storage lifetime follows `self` object
@lru_cache()
def cached_method(self, args):
...
# cached classmethod. the storage lifetime follows `A` class
@lru_cache() # the order is important!
@classmethod # always lru_cache on top of classmethod
def cached_classmethod(self, args):
...
# cached staticmethod. the storage lifetime follows `A` class
@lru_cache() # the order is important!
@staticmethod # always lru_cache on top of staticmethod
def cached_staticmethod(self, args):
...
@lru_cache() # just same as functools.lru_cache
def cached_function():
...
Installation
PyPI is the recommended way.
$ pip install methodtools
- To browse versions and tarballs, visit:
See also
[Documentation](https://methodtools.readthedocs.io/en/latest/)
This project is derived from Ring, a rich cache interface using the same method handling technique.
To learn more about bound method dispatching, see also [wirerope](https://github.com/youknowone/wirerope).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
methodtools-0.4.7.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for methodtools-0.4.7-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e188c780b236adc12e75b5f078c5afb419ef99eb648569fc6d7071f053a1f11 |
|
MD5 | 83f4d1dad204000372e155d91d8aa69d |
|
BLAKE2b-256 | b64b6497ffb463b1b75e04b348ef31070606d43e3c503fa295383538ded999c9 |