Skip to main content

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:

https://pypi.python.org/pypi/methodtools/

See also

Project details


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 details)

Uploaded Source

Built Distribution

methodtools-0.4.7-py2.py3-none-any.whl (4.0 kB view details)

Uploaded Python 2 Python 3

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

Hashes for methodtools-0.4.7.tar.gz
Algorithm Hash digest
SHA256 e213439dd64cfe60213f7015da6efe5dd4003fd89376db3baa09fe13ec2bb0ba
MD5 5b053d748b9199d3594af5508f99bb7b
BLAKE2b-256 133bc21b74ac17befdf17b286494b02221b7a84affb1d410ff86e38ba0e14b13

See more details on using hashes here.

File details

Details for the file methodtools-0.4.7-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for methodtools-0.4.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5e188c780b236adc12e75b5f078c5afb419ef99eb648569fc6d7071f053a1f11
MD5 83f4d1dad204000372e155d91d8aa69d
BLAKE2b-256 b64b6497ffb463b1b75e04b348ef31070606d43e3c503fa295383538ded999c9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page