Remove the warning of getargspec removal

The method getargspec is deprecated and will be removed [1].
This produces a lot of deprecation warning in the logs which is
noisy. This patch proposes to use getfullargspec if it is available.
For python 2 compatibility, we need to fall back to getargspec.

[1] https://docs.python.org/3/library/inspect.html#inspect.getargspec

Change-Id: Ide7d9ca99e0edf23261b5d47f35766aaaac9059b
This commit is contained in:
Hongbin Lu 2018-03-13 18:14:49 +00:00
parent fa5303f058
commit b071b6b216
4 changed files with 14 additions and 6 deletions

View File

@ -14,7 +14,6 @@
"""
import codecs
import inspect
import locale
import logging
import logging.handlers
@ -384,7 +383,7 @@ class App(object):
return 2
cmd_factory, cmd_name, sub_argv = subcommand
kwargs = {}
if 'cmd_name' in inspect.getargspec(cmd_factory.__init__).args:
if 'cmd_name' in utils.getargspec(cmd_factory.__init__).args:
kwargs['cmd_name'] = cmd_name
cmd = cmd_factory(self, self.options, **kwargs)
err = None

View File

@ -13,11 +13,12 @@
"""Discover and lookup command plugins.
"""
import inspect
import logging
import pkg_resources
from . import utils
LOG = logging.getLogger(__name__)
@ -103,7 +104,7 @@ class CommandManager(object):
else:
# NOTE(dhellmann): Some fake classes don't take
# require as an argument. Yay?
arg_spec = inspect.getargspec(cmd_ep.load)
arg_spec = utils.getargspec(cmd_ep.load)
if 'require' in arg_spec[0]:
cmd_factory = cmd_ep.load(require=False)
else:

View File

@ -16,6 +16,7 @@ import sys
import traceback
from . import command
from . import utils
class HelpAction(argparse.Action):
@ -47,7 +48,7 @@ class HelpAction(argparse.Action):
continue
try:
kwargs = {}
if 'cmd_name' in inspect.getargspec(factory.__init__).args:
if 'cmd_name' in utils.getargspec(factory.__init__).args:
kwargs['cmd_name'] = name
cmd = factory(app, None, **kwargs)
if cmd.deprecated:
@ -100,7 +101,7 @@ class HelpCommand(command.Command):
return
self.app_args.cmd = search_args
kwargs = {}
if 'cmd_name' in inspect.getargspec(cmd_factory.__init__).args:
if 'cmd_name' in utils.getargspec(cmd_factory.__init__).args:
kwargs['cmd_name'] = cmd_name
cmd = cmd_factory(self.app, self.app_args, **kwargs)
full_name = (cmd_name

View File

@ -13,6 +13,7 @@
import codecs
import ctypes
import inspect
import os
import struct
import sys
@ -28,6 +29,12 @@ import six
COST = {'w': 0, 's': 2, 'a': 1, 'd': 3}
if hasattr(inspect, 'getfullargspec'):
getargspec = inspect.getfullargspec
else:
getargspec = inspect.getargspec
def damerau_levenshtein(s1, s2, cost):
"""Calculates the Damerau-Levenshtein distance between two strings.