| | |
- __builtin__.object
-
- injector
- memoize
- memoize_method
- null
- proxy
class injector(__builtin__.object) |
| |
Injection of new methods into an existing class
* synopsis *
class some_descriptive_text(injector, some_existing_class,
another_existing_class, ...):
def new_method(self, ...): ...
def another_new_method(self, ...): ...
obj = some_existing_class(...)
obj.new_method(...)
obj = another_existing_class(...)
obj.new_method(...)
# class 'some_descriptive_text' is an empty shell with no use by itself.
* motivation *
The traditional way to add methods to an existing class involves typing
three times the same information:
def new_method(self, ...): ...
existing_class.new_method = new_method
or to defer the naming to after the definition:
def foo(self, ...): ...
existing_class.new_method = foo
A bit of metaclass trickery results in a cleaner syntax. |
| |
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
Data and other attributes defined here:
- __metaclass__ = <class 'libtbx.object_oriented_patterns.__metaclass__'>
|
class memoize(__builtin__.object) |
| |
Memoize the result returned by a function |
| |
Methods defined here:
- __call__(self, *args)
- __init__(self, func)
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class memoize_method(__builtin__.object) |
| |
Memoize the result returned by a bound method.
This is to be used with immutable objects only. |
| |
Methods defined here:
- __get__(self, obj, type=None)
- __init__(self, meth)
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class null(__builtin__.object) |
| | |
Methods defined here:
- __call__(self, *args, **kwds)
- __delattr__(self, a)
- __delitem__(self, i)
- __getattr__(self, a)
- __getitem__(self, i)
- __init__(self, *args, **kwds)
- __nonzero__(self)
- __repr__(self)
- __setattr__(self, a, v)
- __setitem__(self, i, v)
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
class proxy(__builtin__.object) |
| | |
Methods defined here:
- __getattr__(self, attr)
- __init__(self, subject)
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
| |