Skip to content

Commit

Permalink
Replace functools.wraps with six.wraps
Browse files Browse the repository at this point in the history
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 <vfeenstr@redhat.com>
  • Loading branch information
vinzenz committed Oct 27, 2020
1 parent 287d684 commit 3ee84c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions leapp/utils/clicmd.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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('')
Expand Down
9 changes: 5 additions & 4 deletions leapp/utils/deprecation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import datetime
import functools
import inspect
import warnings
from collections import namedtuple

import six

from leapp.models import Model


Expand Down Expand Up @@ -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 ...
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3ee84c0

Please sign in to comment.