Skip to main content

decorator toolkit library

Project description

DecTools provides a library of tools for creating Python decorators. It unifies usage between class decorators, decorators requiring arguments, and simple decorators. It also provides correct names, doc, and function signatures for decorated functions. Typical usage often looks like this:

@make_call_once
def register_callback(function):
      gui.callback_create(function.__name__, function)

@make_call_before
def require_login(function, args, kwargs, page_name):
     while not current_user_id():
        ...

@register
@require_login("Summary of Items")
def view_summary():
    ...

This release has @make_call_(once/before/after/instead). It also has commonly used decorators in this release, including:

  • @pre, @post for pre and post condition processing

  • @log() for logging function calls

  • @invariant, a class decorator, for contract programming

Thanks

Thanks to Michele Simionato for exposing utility functions in Decorator Decorator and to David Mertz for his excellent IBM Developer Works article “Charming Python: Decorators make magic easy”, http://www.ibm.com/developerworks/linux/library/l-cpdecor.html

Contact

You can contact the author, Charles Merriam, at charles.merriam@gmail.com. Or visit http://charlesmerriam.com

Other Notes

This is a ‘shared experiment’ release.

This package depends on “decorator”, 3.1.2 or above, http://pypi.python.org/pypi/decorator/3.1.2

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

dectools-0.1.1.tar.gz (3.5 MB view hashes)

Uploaded Source

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