Skip to main content

Class, function, and metaclass 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? Want to get metaclass features without creating metaclasses? How about synchronized methods?

“DecoratorTools” gets you all of this and more. 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.6:

  • Added synchronized decorator to support locking objects during method execution.

Changes since version 1.5:

  • Added classy base class that allows you to do the most often-needed metaclass behviors without needing an actual metaclass.

Changes since version 1.4:

  • Added enclosing_frame() function, so that complex decorators that call DecoratorTools functions while being called by DecoratorTools functions, will work correctly.

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.7.zip (27.5 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.7-py2.5.egg (28.1 kB view details)

Uploaded Egg

DecoratorTools-1.7-py2.4.egg (28.6 kB view details)

Uploaded Egg

DecoratorTools-1.7-py2.3.egg (81.7 kB view details)

Uploaded Egg

File details

Details for the file DecoratorTools-1.7.zip.

File metadata

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

File hashes

Hashes for DecoratorTools-1.7.zip
Algorithm Hash digest
SHA256 55283e6acc4e5f66cb6e104f98d08f93b1bd29823d17d7e2f852541738a53a11
MD5 84df0a86aabec6a7d802439ffaa17585
BLAKE2b-256 f0b016578ca82cc725d8d9085584c57f92e541642d2868db785c84845e06fd60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for DecoratorTools-1.7-py2.5.egg
Algorithm Hash digest
SHA256 cb8ad66bffb215ad1aa8a83e59549ee0062042d70c077bf66322e4a0da58d2a8
MD5 d205a59fc13405c8a2f1c355ee12a599
BLAKE2b-256 7659b0a30760bf0b6528d0f52dc39f2ad3119bbbad16a5b3f186c47f952b7fa3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for DecoratorTools-1.7-py2.4.egg
Algorithm Hash digest
SHA256 5990e62e921eef3a4e3bd32ab59bae10c2602840b3a609d5e26f7669008f8aaf
MD5 4f850ac078879e5f38b80bcd90db9999
BLAKE2b-256 176ed589165198159db3686d5bc61bc2551e84e30a1eec8c37b7d8591eab6087

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for DecoratorTools-1.7-py2.3.egg
Algorithm Hash digest
SHA256 f9c804e20d05ad18cf0bf5e52c5afb53665034f425215923059f1064dbea7a6a
MD5 996acd2d49f7ae96fcc593d597c36a3c
BLAKE2b-256 fca0d308dfe406f6380c75d4d1613aa7ce8d6bd66aecafc39405d9196de68f51

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