Permalink
Browse files

added function attribute manipulator classes

  • Loading branch information...
1 parent 740d70d commit b664ce1d94efccd6c43fbccf44ebdd7a086c7bc2 @herczy committed Mar 31, 2012
Showing with 22 additions and 3 deletions.
  1. +22 −3 codega/decorators.py
View
@@ -1,18 +1,37 @@
'''Various commonly used function decorators'''
+def set_attributes(name, doc=None):
+ '''
+ Set the name and documentation attributes to the decorated function
+ '''
+
+ def __decorator(func):
+ func.__name__ = name
+ func.__doc__ = doc
+
+ return func
+
+ return __decorator
+
+def copy_attributes(base):
+ '''
+ Copy name and documentation attributes of base
+ to the decorated function.
+ '''
+
+ return set_attributes(base.__name__, doc=base.__doc__)
+
def abstract(func):
'''The class method is an abstract.
Arguments:
func -- Decorated function. Will never be called
'''
+ @copy_attributes(func)
def __wrapper(self, *args, **kwargs):
raise NotImplementedError("%s.%s is an abstract method" % (self.__class__.__name__, func.__name__))
- __wrapper.__name__ = func.__name__
- __wrapper.__doc__ = func.__doc__
-
return __wrapper
def init_mark(func):

0 comments on commit b664ce1

Please sign in to comment.