| Home | Trees | Indices | Help |
|---|
|
|
Various utilities.
|
|||
|
memoize Decorator to use automatic memoization on a given function, such that results are chached and, if called a second time, the function will return the cached value. |
|||
|
lazy_attribute Decorator that will turn a method in a lazy attribute. |
|||
|
BooleanContext This class represents an boolean variable with RAII setting within a scope. |
|||
| NamedTupleMeta | |||
|
NamedTuple Immutable object that acts like a dictionary whose members can also be set via attribute access. |
|||
|
Bindable Utility base class for general bindable function objects. |
|||
|
CallCounter Function object that counts the number of times it is called. |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
mixin = <_Framework.Util.memoize object at 0x101bb8050>
|
|||
__package__ =
|
|||
|
|||
Decorator that injects the decorated function into the 'target' class. If no name is given the decorated function name will be used for the injected method name. If the class already has a method with a given name it raises an error unless 'override' is set to True. Example:
class MyClass(object):
pass
@monkeypatch(MyClass)
def patched_method(self):
print "Lalala"
MyClass().patched_method()
Output: Lalala |
Decorator that injects the decorated function as an extension of a method of the 'target' class. If no 'name' is passed, the decorated function name will be the name of the method. Example:
class MyClass(object):
def some_method(self):
print "Original"
@monkeypatch_extend(MyClass)
def some_method(self):
print "Patch"
MyClass().some_method()
Output: Original Patch Known issues: if you are extending a method of class Deriv, when the method is only defined in its super-class Base (i.e. not overriden by Deriv but is inherited from Base), can break the ability of the method to properly cooperate (i.e. propagate calls to super in a diamond-shaped hierarchy [1]). If monkeypatch_extend in a metaclass, this can be worked around by injecting a cooperative definition of the method in Deriv's dictionary. An example of this can be seen in SubjectSlot.SubjectMeta [1] A definition of cooperative method http://sinusoid.es/jpblib/coop.html |
Meta-decorator to define decorators that decorate a method in a concrete instance. The decorator method will be passed the object instance as first argument and the unbound decorated method as second argument. The decorator method will be called lazily the first time the method is accessed. For an example see @signal_slot in SubjectSlot module. |
Property that forwards access to a nested object. You can use it as a decorator, where the function will be used only to extract the name of the property. It is useful when exposing some property of a subobject... Example:
class NestedClass(object):
parameter = 0
class SomeClass(object):
def __init__(self, *a, **k):
super(SomeClass, self).__init__(*a, **k)
self._nested_object = NestedClass()
@forward_property('_nested_object')
def parameter(): pass
print SomeClass().parameter
Output: 0 |
Flattens a list of lists into a new list. It does not do that recursively, only one level. |
Returns the index of the first element in sequence 'seq' satisfying predicate. If no such element exists returns the length of the sequence. |
Returns a new dictionary with all the entries in dictionaries 'a' and 'b'. In case of conflict the entry from 'b' is taken. |
Maps a tree-like data structure built by composing sequences of type iterable_type. if no iterable_type is given, it is assumed to be the type of the root element. Example:
print recurse_map(lambda t: t + (0,),
[[(0,), (1,)], [(3,), (4,)]])
Output: [[(0,0), (1,0)], [(3,0), (4,0)]] |
Returns the composition of all passed functions, similar to the mathematical dot. Example: f = lambda x: x + 2 g = lambda x: x * 2 h = compose(f, g) print h(3) Output: 8 # (3 * 2) + 2 |
contextlib.contextmanager have the consumes the generator, so most of the time they can only be used one. This variant will always re-instantiate the generator, such that the context manager can be reused. |
Prints value and returns value. Useful when debugging the results of sub-expressions. |
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Wed Mar 6 18:53:31 2013 | http://epydoc.sourceforge.net |