Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace functools.wraps with six.wraps #674

Merged
merged 1 commit into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions leapp/utils/clicmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from argparse import ArgumentParser, _SubParsersAction, RawDescriptionHelpFormatter

import six

from leapp.exceptions import CommandDefinitionError, UsageError, CommandError


Expand Down Expand Up @@ -277,7 +279,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 Expand Up @@ -324,4 +326,4 @@ def command_aware_wraps(f):
additional = ()
if hasattr(f, 'command'):
additional = ('command',)
return functools.wraps(f, assigned=functools.WRAPPER_ASSIGNMENTS + additional)
return six.wraps(f, assigned=functools.WRAPPER_ASSIGNMENTS + additional)
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
12 changes: 12 additions & 0 deletions tests/scripts/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import leapp.utils.audit
from leapp.messaging.inprocess import InProcessMessaging
from leapp.repository.scan import scan_repo
from leapp.utils.deprecation import suppress_deprecation, deprecated


@pytest.fixture(scope='module')
Expand All @@ -34,3 +35,14 @@ def test_deprecations(repository):
entries = [entry for entry in entries
if datetime.datetime.strptime(entry['stamp'].rstrip('Z'), '%Y-%m-%dT%H:%M:%S.%f') > start]
assert entries and len(entries) == 5


# This is test to show the current suppress_deprecation limitation
@deprecated(since='2011-11-11', message='never to be seen')
def foobar():
pass


@suppress_deprecation(foobar)
def test_suppress_with_fixture(monkeypatch):
assert monkeypatch