From 59a96b73f179cbd4428b15fa5b040855f65ebe41 Mon Sep 17 00:00:00 2001 From: Eyal Date: Mon, 15 Apr 2019 10:30:20 +0300 Subject: [PATCH] inspect.getargspec is deprecated on py3 use inspect.getfullargspec instead Change-Id: Ibdadb08b23738490646db676312bc87c3bf27eaa --- mistral/utils/inspect_utils.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mistral/utils/inspect_utils.py b/mistral/utils/inspect_utils.py index c1dcd7e72..fd856fc96 100644 --- a/mistral/utils/inspect_utils.py +++ b/mistral/utils/inspect_utils.py @@ -15,6 +15,8 @@ import inspect import json +import six + def get_public_fields(obj): """Returns only public fields from object or class.""" @@ -42,7 +44,7 @@ def get_docstring(obj): def get_arg_list(func): - argspec = inspect.getargspec(func) + argspec = get_args_spec(func) args = argspec.args @@ -57,7 +59,7 @@ def get_arg_list_as_str(func): if args: return args - argspec = inspect.getargspec(func) + argspec = get_args_spec(func) defs = list(argspec.defaults or []) args = get_arg_list(func) @@ -79,7 +81,14 @@ def get_arg_list_as_str(func): else: arg_str_list.append("%s" % args[index]) - if argspec.keywords: - arg_str_list.append("**%s" % argspec.keywords) + keywords = argspec.keywords if six.PY2 else argspec.varkw + if keywords: + arg_str_list.append("**%s" % keywords) return ", ".join(arg_str_list) + + +def get_args_spec(func): + if six.PY2: + return inspect.getargspec(func) + return inspect.getfullargspec(func)