Skip to main content

Use class and function decorators -- even in Python 2.3!

Project description

Want to use decorators, but still need to support Python 2.3? Wish you could have class decorators, decorate arbitrary assignments, or match decorated function signatures to their original functions? Then you need “DecoratorTools”. Some quick examples:

# Method decorator example
from peak.util.decorators import decorate

class Demo1(object):
    decorate(classmethod)   # equivalent to @classmethod
    def example(cls):
        print "hello from", cls


# Class decorator example
from peak.util.decorators import decorate_class

def my_class_decorator():
    def decorator(cls):
        print "decorating", cls
        return cls
    decorate_class(decorator)

class Demo2:
    my_class_decorator()

# "decorating <class Demo2>" will be printed when execution gets here

Installing DecoratorTools (using "easy_install DecoratorTools" or "setup.py install") gives you access to the peak.util.decorators module. The tools in this module have been bundled for years inside of PEAK, PyProtocols, RuleDispatch, and the zope.interface package, so they have been widely used and tested. (Unit tests are also included, of course.)

This standalone version is backward-compatible with the bundled versions, so you can mix and match decorators from this package with those provided by zope.interface, TurboGears, etc.

For complete documentation, see the DecoratorTools manual.

Changes since version 1.2:

  • Added rewrap() function and template_function decorator to support signature matching for decorated functions. (These features are similar to the ones provided by Michele Simionato’s “decorator” package, but do not require Python 2.4 and don’t change the standard idioms for creating decorator functions.)

  • decorate_class() will no longer apply duplicate class decorator callbacks unless the allow_duplicates argument is true.

Changes since version 1.1:

  • Fixed a problem where instances of different struct types could equal each other

Changes since version 1.0:

  • The struct() decorator makes it easy to create tuple-like data structure types, by decorating a constructor function.

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

DecoratorTools-1.3.zip (22.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

DecoratorTools-1.3-py2.5.egg (22.7 kB view details)

Uploaded Egg

DecoratorTools-1.3-py2.4.egg (23.1 kB view details)

Uploaded Egg

DecoratorTools-1.3-py2.3.egg (62.1 kB view details)

Uploaded Egg

File details

Details for the file DecoratorTools-1.3.zip.

File metadata

  • Download URL: DecoratorTools-1.3.zip
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for DecoratorTools-1.3.zip
Algorithm Hash digest
SHA256 f42cd70c1eaa4a0418dd3a919587815f77dfbd83bb34d9dd6a508c2f4fa0f084
MD5 ef0c7a0379422d47c8a51dcfc90135cd
BLAKE2b-256 0476dee6722bdf3b6f2879045b93be394ec26361a387ae3c4261a4112ab4f540

See more details on using hashes here.

File details

Details for the file DecoratorTools-1.3-py2.5.egg.

File metadata

File hashes

Hashes for DecoratorTools-1.3-py2.5.egg
Algorithm Hash digest
SHA256 4a7d59bf44e14afb9a507ad83026fd2fe06a4501c32a2d132ca3962a019c1d00
MD5 7743d47d5acce85bcb9318ad8d63efe2
BLAKE2b-256 b5e90319416e54aaacbb6dd89b7148ee3e85bc38c15ad2cbf6d477a19b822799

See more details on using hashes here.

File details

Details for the file DecoratorTools-1.3-py2.4.egg.

File metadata

File hashes

Hashes for DecoratorTools-1.3-py2.4.egg
Algorithm Hash digest
SHA256 a741963c4d63e8d7ed6e8d8a15514cce94e3a409399099801322032f3d8f3ae0
MD5 4052cbdd046a50742a887c870fd6839d
BLAKE2b-256 25dfb3d3954cf0188b0f0bee89a6302874f7519cae4623d7e9aa0e62c66aa7d7

See more details on using hashes here.

File details

Details for the file DecoratorTools-1.3-py2.3.egg.

File metadata

File hashes

Hashes for DecoratorTools-1.3-py2.3.egg
Algorithm Hash digest
SHA256 f838863508b60a4ddbd122daa13d07e2d759391028cce0d4044e591dfd9fc450
MD5 7e56a55f4cd57d3e8edcbdf3088ef6e3
BLAKE2b-256 e7ad3ae79b6d97244392e46501eb9cd3592ba3c690e4756186db78dd1c565b83

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