Skip to main content

Expand standard functools to methods

Project description

https://github.com/youknowone/methodtools/actions/workflows/python-package.yml/badge.svg https://codecov.io/gh/youknowone/methodtools/graph/badge.svg

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.5.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file methodtools-0.4.5.tar.gz.

File metadata

  • Download URL: methodtools-0.4.5.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for methodtools-0.4.5.tar.gz
Algorithm Hash digest
SHA256 9370156e9036789e98cf0e97355b3be3bcd7cc9e520d1e15893a1407719effb2
MD5 0fb2eb2b93b116059ac096f9fb5568e0
BLAKE2b-256 2b13973a50bb3802d4e915c291fc9b4df034dc91dc07b442cbb186eda7b117f4

See more details on using hashes here.

Supported by

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