Replace use of functools.wraps() with six.wraps()

In Python 2.7, functools.wraps() does not provide the '__wrapped__'
attribute. This attribute is used by
oslo_utils.reflection.get_signature() when getting the signature of a
function. If a function is decorated without the '__wrapped__'
attribute then the signature will be of the decorator rather than the
underlying function.

From the six documentation for six.wraps():
    This is exactly the functools.wraps() decorator, but it sets the
    __wrapped__ attribute on what it decorates as functools.wraps()
    does on Python versions after 3.2.

Change-Id: I11bf2fa945d36bfbc89ec8239e7c9259e3e12496
This commit is contained in:
John L. Villalovos 2018-02-01 16:32:48 -08:00
parent 81de9dc06e
commit 15d5958e17
3 changed files with 8 additions and 8 deletions

View File

@ -11,12 +11,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import functools
import os
import re
import flask
from oslo_utils import uuidutils
import six
import werkzeug
from ironic_inspector import api_tools
@ -70,7 +70,7 @@ def error_response(exc, code=500):
def convert_exceptions(func):
@functools.wraps(func)
@six.wraps(func)
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
@ -168,7 +168,7 @@ def api(path, is_public_api=False, rule=None, verb_to_rule_map=None,
def outer(func):
@app.route(path, **flask_kwargs)
@convert_exceptions
@functools.wraps(func)
@six.wraps(func)
def wrapper(*args, **kwargs):
flask.request.context = context.RequestContext.from_environ(
flask.request.environ,

View File

@ -14,7 +14,6 @@
"""Base code for PXE boot filtering."""
import contextlib
import functools
from automaton import exceptions as automaton_errors
from automaton import machines
@ -23,6 +22,7 @@ from futurist import periodics
from oslo_concurrency import lockutils
from oslo_config import cfg
from oslo_log import log
import six
import stevedore
from ironic_inspector.common.i18n import _
@ -74,7 +74,7 @@ State_space = [
def locked_driver_event(event):
"""Call driver method having processed the fsm event."""
def outer(method):
@functools.wraps(method)
@six.wraps(method)
def inner(self, *args, **kwargs):
with self.lock, self.fsm_reset_on_error() as fsm:
fsm.process_event(event)

View File

@ -12,7 +12,6 @@
# limitations under the License.
import copy
import functools
import json
import os
import shutil
@ -26,6 +25,7 @@ from oslo_config import cfg
from oslo_serialization import base64
from oslo_utils import timeutils
from oslo_utils import uuidutils
import six
from ironic_inspector.common import ironic as ir_utils
from ironic_inspector import db
@ -524,7 +524,7 @@ class TestProcessNode(BaseTest):
@mock.patch.object(node_cache, 'get_node', autospec=True)
class TestReapply(BaseTest):
def prepare_mocks(func):
@functools.wraps(func)
@six.wraps(func)
def wrapper(self, pop_mock, *args, **kw):
pop_mock.return_value = node_cache.NodeInfo(
uuid=self.node.uuid,
@ -600,7 +600,7 @@ class TestReapplyNode(BaseTest):
self.node_info.release_lock.assert_called_once_with(self.node_info)
def prepare_mocks(fn):
@functools.wraps(fn)
@six.wraps(fn)
def wrapper(self, release_mock, finished_mock, swift_mock,
*args, **kw):
finished_mock.side_effect = lambda *a, **kw: \