Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added function attribute manipulator classes

  • Loading branch information...
commit b664ce1d94efccd6c43fbccf44ebdd7a086c7bc2 1 parent 740d70d
@herczy authored
Showing with 22 additions and 3 deletions.
  1. +22 −3 codega/decorators.py
View
25 codega/decorators.py
@@ -1,5 +1,26 @@
'''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.
@@ -7,12 +28,10 @@ def abstract(func):
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):
Please sign in to comment.
Something went wrong with that request. Please try again.