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
Built Distribution
File details
Details for the file methodtools-0.4.7.tar.gz
.
File metadata
- Download URL: methodtools-0.4.7.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e213439dd64cfe60213f7015da6efe5dd4003fd89376db3baa09fe13ec2bb0ba |
|
MD5 | 5b053d748b9199d3594af5508f99bb7b |
|
BLAKE2b-256 | 133bc21b74ac17befdf17b286494b02221b7a84affb1d410ff86e38ba0e14b13 |
File details
Details for the file methodtools-0.4.7-py2.py3-none-any.whl
.
File metadata
- Download URL: methodtools-0.4.7-py2.py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e188c780b236adc12e75b5f078c5afb419ef99eb648569fc6d7071f053a1f11 |
|
MD5 | 83f4d1dad204000372e155d91d8aa69d |
|
BLAKE2b-256 | b64b6497ffb463b1b75e04b348ef31070606d43e3c503fa295383538ded999c9 |