summaryrefslogtreecommitdiff
path: root/taskflow/utils
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2014-12-05 14:28:21 -0800
committerJoshua Harlow <harlowja@yahoo-inc.com>2014-12-12 12:39:57 -0800
commita440ec40a518f8ee25ba5a945847e5b4eefdb45c (patch)
tree54b454a3731509fc552f74cc498c111ef947ed84 /taskflow/utils
parent1c7d242033c2ebf34ab73c6ba32308b9bba30ffd (diff)
downloadtaskflow-a440ec40a518f8ee25ba5a945847e5b4eefdb45c.tar.gz
Add a moved_inheritable_class deprecation helper
For cases where inheritance is still needed we should provide a mechanism to provide this so that consuming users of the library can still refer to the old location for a period of time so that there derived code does not fail due to the movement of the class that occurred. Change-Id: I8cd5b707125264f6b595d5b3ac327cfe16e7923c
Diffstat (limited to 'taskflow/utils')
-rw-r--r--taskflow/utils/deprecation.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/taskflow/utils/deprecation.py b/taskflow/utils/deprecation.py
index a108676..f70d767 100644
--- a/taskflow/utils/deprecation.py
+++ b/taskflow/utils/deprecation.py
@@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import functools
import warnings
import six
@@ -202,6 +203,45 @@ def moved_property(new_attribute_name, message=None,
stacklevel=stacklevel)
+def moved_inheritable_class(new_class, old_class_name, old_module_name,
+ message=None, version=None, removal_version=None):
+ """Deprecates a class that was moved to another location.
+
+ NOTE(harlowja): this creates a new-old type that can be used for a
+ deprecation period that can be inherited from, the difference between this
+ and the ``moved_class`` deprecation function is that the proxy from that
+ function can not be inherited from (thus limiting its use for a more
+ particular usecase where inheritance is not needed).
+
+ This will emit warnings when the old locations class is initialized,
+ telling where the new and improved location for the old class now is.
+ """
+ old_name = ".".join((old_module_name, old_class_name))
+ new_name = reflection.get_class_name(new_class)
+ prefix = _CLASS_MOVED_PREFIX_TPL % (old_name, new_name)
+ out_message = _generate_moved_message(prefix,
+ message=message, version=version,
+ removal_version=removal_version)
+
+ def decorator(f):
+
+ # Use the older functools until the following is available:
+ #
+ # https://bitbucket.org/gutworth/six/issue/105
+
+ @functools.wraps(f, assigned=("__name__", "__doc__"))
+ def wrapper(self, *args, **kwargs):
+ deprecation(out_message, stacklevel=3)
+ return f(self, *args, **kwargs)
+
+ return wrapper
+
+ old_class = type(old_class_name, (new_class,), {})
+ old_class.__module__ = old_module_name
+ old_class.__init__ = decorator(old_class.__init__)
+ return old_class
+
+
def moved_class(new_class, old_class_name, old_module_name, message=None,
version=None, removal_version=None, stacklevel=3):
"""Deprecates a class that was moved to another location.