summaryrefslogtreecommitdiff
path: root/silx/utils/proxy.py
diff options
context:
space:
mode:
Diffstat (limited to 'silx/utils/proxy.py')
-rw-r--r--silx/utils/proxy.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/silx/utils/proxy.py b/silx/utils/proxy.py
index 7d7d662..8711799 100644
--- a/silx/utils/proxy.py
+++ b/silx/utils/proxy.py
@@ -1,7 +1,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2016-2018 European Synchrotron Radiation Facility
+# Copyright (c) 2016-2019 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -30,6 +30,8 @@ __authors__ = ["V. Valls"]
__license__ = "MIT"
__date__ = "02/10/2017"
+
+import functools
import six
@@ -202,3 +204,38 @@ class Proxy(object):
__irepeat__ = property(lambda self: self.__obj.__irepeat__)
__call__ = property(lambda self: self.__obj.__call__)
+
+
+def _docstring(dest, origin):
+ """Implementation of docstring decorator.
+
+ It patches dest.__doc__.
+ """
+ if not isinstance(dest, type) and isinstance(origin, type):
+ # func is not a class, but origin is, get the method with the same name
+ try:
+ origin = getattr(origin, dest.__name__)
+ except AttributeError:
+ raise ValueError(
+ "origin class has no %s method" % dest.__name__)
+
+ dest.__doc__ = origin.__doc__
+ return dest
+
+
+def docstring(origin):
+ """Decorator to initialize the docstring from another source.
+
+ This is useful to duplicate a docstring for inheritance and composition.
+
+ If origin is a method or a function, it copies its docstring.
+ If origin is a class, the docstring is copied from the method
+ of that class which has the same name as the method/function
+ being decorated.
+
+ :param origin:
+ The method, function or class from which to get the docstring
+ :raises ValueError:
+ If the origin class has not method n case the
+ """
+ return functools.partial(_docstring, origin=origin)