From 3ee84c005e609dac4f016ac762161740009b1f4c Mon Sep 17 00:00:00 2001 From: Vinzenz Feenstra Date: Tue, 27 Oct 2020 09:30:37 +0100 Subject: [PATCH] Replace functools.wraps with six.wraps Previously we have been using functools.wraps. However if any decorator that uses functools.wraps is used, some code that relies on __wrapped__ being present, e.g. pytest, will fail on Python2. Switching to six.wraps will solve this problem, as it introduces this change as well and solves the missing __wrapped__ attribute. Signed-off-by: Vinzenz Feenstra --- leapp/utils/clicmd.py | 5 +++-- leapp/utils/deprecation.py | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/leapp/utils/clicmd.py b/leapp/utils/clicmd.py index 4da80833f..16686dbd8 100644 --- a/leapp/utils/clicmd.py +++ b/leapp/utils/clicmd.py @@ -1,9 +1,10 @@ -import functools import os import sys from argparse import ArgumentParser, _SubParsersAction, RawDescriptionHelpFormatter +import six + from leapp.exceptions import CommandDefinitionError, UsageError, CommandError @@ -277,7 +278,7 @@ def wrapper(f): def _ensure_command(wrapped): - @functools.wraps(wrapped) + @six.wraps(wrapped) def wrapper(f): if not hasattr(f, 'command'): f.command = Command('') diff --git a/leapp/utils/deprecation.py b/leapp/utils/deprecation.py index 5ce511a2c..d1647a9b8 100644 --- a/leapp/utils/deprecation.py +++ b/leapp/utils/deprecation.py @@ -1,9 +1,10 @@ import datetime -import functools import inspect import warnings from collections import namedtuple +import six + from leapp.models import Model @@ -31,7 +32,7 @@ def decorator(item): ' Use the decorator on the affected methods instead of the current class.' ) - @functools.wraps(target_item) + @six.wraps(target_item) def process_wrapper(*args, **kwargs): # we need to remove later just items that we add right now # added_items == new items we add now to ... @@ -106,14 +107,14 @@ def do_warn(): if inspect.isclass(item): old_init = item.__init__ - @functools.wraps(item.__init__, assigned=('__name__', '__doc__')) + @six.wraps(item.__init__, assigned=('__name__', '__doc__')) def wrapper(*args, **kwargs): do_warn() return old_init(*args, **kwargs) item.__init__ = wrapper result = item else: - @functools.wraps(item) + @six.wraps(item) def wrapper(*args, **kwargs): do_warn() return item(*args, **kwargs)