Handle deprecation of inspect.getargspec

getargspec has been deprecated in py3 with plans to remove it in py3.6.
The recommendation is to move to inspect.signature, but the results of
that call are different than the existing one.

There is also getfullargspec available under py3 that was originally
deprecated, but for the sake of handling 2/3 code, it has been
un-deprecated. This call uses inspect internally, but returns a mostly
compatible result with what getargspec did. This handles getargspec
deprecation by just using getfullargspec instead if it is available

Closes-Bug: #1766919

Change-Id: I154b1ef14dbace803841cb3eed3ff02dd0020588
This commit is contained in:
Stephen Finucane
2018-01-02 17:18:21 +00:00
committed by Matt Riedemann
parent d6bde3bee4
commit 35b304661d
6 changed files with 20 additions and 15 deletions

View File

@@ -95,6 +95,12 @@ _FILE_CACHE = {}
_SERVICE_TYPES = service_types.ServiceTypes()
if hasattr(inspect, 'getfullargspec'):
getargspec = inspect.getfullargspec
else:
getargspec = inspect.getargspec
def get_root_helper():
if CONF.workarounds.disable_rootwrap:
cmd = 'sudo'
@@ -748,8 +754,8 @@ def expects_func_args(*args):
@functools.wraps(dec)
def _decorator(f):
base_f = safe_utils.get_wrapped_function(f)
arg_names, a, kw, _default = inspect.getargspec(base_f)
if a or kw or set(args) <= set(arg_names):
argspec = getargspec(base_f)
if argspec[1] or argspec[2] or set(args) <= set(argspec[0]):
# NOTE (ndipanov): We can't really tell if correct stuff will
# be passed if it's a function with *args or **kwargs so
# we still carry on and hope for the best