Tag : decorator
|Class decorator to check that methods are implemented.||Jeffrey Fischer||python||Class decorator check that methods implemented. decorators||
This decorator wraps the class's __init__ function to check that provided set of methods is present on the instantiated class. This is useful for avoiding inheritance in mix-in classes. We can inherit directly from object and still make it clear what methods we expect in other classes to be combined with the mix-in.
Requires at least Python 2.6, which added class decorators.
|May 27, 2011|
|Item Properties||Ian Kelly||python||decorator descriptor oop property||
A property variation that allows property access using an index or key.
|May 18, 2011|
|Abstract method decorator||Alessandro Presta||python||abstract decorator exception inheritance method python subclass||
A simple decorator that helps define abstract methods: when such a method is called, an appropriate exception is raised.
|April 19, 2011|
|Composition of classes instead of multiple inheritance||Ethan Furman||python||class_decorator composition inheritance multiple_inheritance||
MI can be difficult and confusing, and if the base classes don't cooperate -- well, cooperative MI won't work.
One way around this is to use composition instead. This class decorator will combine the source classes with the target class, ensuring that no duplications occur (raises a TypeError if there are any).
|April 16, 2011|
|Decorators for adding aliases to methods in a class||José Nahuel Cuesta Luengo||python||alias decorator||
The following recipe can be used as a means to adding aliases to methods in a class.
|April 16, 2011|
|decorator accepts any argument||kylewu||Python||Decorator||April 13, 2011|
|Connect PyGTK object events to class methods automatically||Pavel Krc||python||automate connect decorator event pygtk||
A module that allows you to not to repeat yourself (DRY) while writing typical PyGTK constructions (an object containing PyGTK widgets with its methods servicing widget events) by calling connect() automatically. See docstring.
|February 17, 2011|
|Trace decorator for debugging||Kevin L. Sitze||python||classes debug debugging decorators functions inspection modules trace||
This package provides a decorator for tracing function and method calls in your applications. The tracing capabilities are managed through the logging package, and several mechanisms are provided for controlling the destination of the trace output.
It also provides functionality for adding decorators to existing classes or modules.
|January 24, 2011|
|Counting decorator||nibrahim||python||decorators testing||
To be used as a decorator for a function that will maintain the number of times it was called. Here is an example use.
|January 7, 2011|
|Simple local cache and cache decorator||Andrey Nikishaev||python||cache decorator memoization python||
Simple local cache. It saves local data in singleton dictionary with convenient interface
Examples of use:
|December 8, 2010|
|Named Sequences for environments containing large numbers of POD instances||Kevin L. Sitze||python||decorator memory sequence slot unittests||
Generate classes with named data attributes that can be sequenced. Useful for POD classes for which many records will exist concurrently.
Compare the feature set to NamedTuples by Raymond Hettinger: http://code.activestate.com/recipes/500261-named-tuples/
|November 27, 2010|
|Keyword Argument Injection with Python Decorators||Ahmet Emre Aladağ||python||class class_decorator decorator injection variable||
In most of the object oriented codes we write, we need to set class attributes to the given argument values and this is a very line-consuming thing. To get over these redundant lines, I found a solution using decorators.
|September 5, 2010|
|Method signature type checking decorator for Python 3.0||andrew johnson||python||checking decorator method signature type||
Clean lightweight type-checking with Python 3.0 annotations.
|July 10, 2010|
|Decorator to expose local variables of a function after execution||Pietro Berkes||python||decorator function inner local scope variables||
Decorator to expose the local variables defined in the inner scope of a function. At the exit of the decorated function (regular exit or exceptions), the local dictionary is copied to a read-only property,
The main implementation is based on injecting bytecode into the original function, and requires the lightweight module
|July 7, 2010|
|Decorator to expose local variables of a function after execution [alternative implementation]||Andrea Maffezzoli||python||decorator function inner local scope variables||
Please note that the present is a fork of the recipe 577283 "Decorator to expose local variables of a function after execution" of Pietro Berkes, available at http://code.activestate.com/recipes/577283-decorator-to-expose-local-variables-of-a-function-/ , and aiming only to report the alternative implementation "persistent_locals2", whose I'm co-author with Pietro Berkes, and which was submitted together to the original recipe. Refer to the latter for an exhaustive description and discussion.
|July 7, 2010|