Skip to main content

Use class and function decorators -- even in Python 2.3 (now with source debugging for generated code)!

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.3:

  • Added support for debugging generated code, including the code generated by rewrap() and template_function.

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.4.zip (23.6 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.4-py2.5.egg (24.4 kB view details)

Uploaded Egg

DecoratorTools-1.4-py2.4.egg (24.8 kB view details)

Uploaded Egg

DecoratorTools-1.4-py2.3.egg (67.6 kB view details)

Uploaded Egg

File details

Details for the file DecoratorTools-1.4.zip.

File metadata

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

File hashes

Hashes for DecoratorTools-1.4.zip
Algorithm Hash digest
SHA256 a21dfda98c792b8008bdc65b1320595cab7016d612e1e74813ee0f6310a338d6
MD5 8b073d17ba19d9d053731e668a4e36e0
BLAKE2b-256 2437baa9fc4ceda5772a122e5111f31e5837e648205fe85156498eec5525c3ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for DecoratorTools-1.4-py2.5.egg
Algorithm Hash digest
SHA256 e3389b8033cb1b25ee34d785c0bc38982ff389e6a8557e1ef26b9f432a699261
MD5 c383d145770eae60552d22830e752e10
BLAKE2b-256 44645c6002f80ecedafef1424e8e79045ae324dbf3b830ea2fc067d3ba9ac29d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for DecoratorTools-1.4-py2.4.egg
Algorithm Hash digest
SHA256 ac1c5d157df6b18530205c18641fdbb67975c2737a0c087de152827bcdf58040
MD5 cf52143c5d79f3553c9dca35a3ecdd59
BLAKE2b-256 84ec7e526cdc2f29c11a6f7c8c60d6033b61fe1a73fd194eace77a21e20c4602

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for DecoratorTools-1.4-py2.3.egg
Algorithm Hash digest
SHA256 2788d001dc1af0045e2d015157b5d49be737ae7d567838ca72272f87c4bca1e4
MD5 730ee52a76c780948d2ba113ca5d6c9e
BLAKE2b-256 2d81fe53e0ccb8939431264b1b7cfa515c6eec5f8d100ef10e9f4e5736647838

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