Replace getargspec with getfullargspec

inspect.getargspec() is deprecated since py3

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

Change-Id: If1721576706aff3e242ea9b19910c7e334939384
This commit is contained in:
likui 2021-05-12 17:29:29 +08:00
parent 368cddec91
commit a449cda21b
3 changed files with 6 additions and 21 deletions

View File

@ -17,22 +17,17 @@
import abc
import inspect
if hasattr(inspect, 'getfullargspec'):
getargspec = inspect.getfullargspec
else:
getargspec = inspect.getargspec
def _get_arg_count(method):
"""Get the number of args for a method.
"""Get the number of positional parameters for a method.
:param method: The method to check.
:returns: The number of args for the method.
:returns: The number of positional parameters for the method.
"""
if not method:
return 0
arg_spec = getargspec(method)
arg_spec = inspect.getfullargspec(method)
return len(arg_spec[0])

View File

@ -22,11 +22,6 @@ import tooz.locking
from cinder import coordination
from cinder.tests.unit import test
if hasattr(inspect, 'getfullargspec'):
getargspec = inspect.getfullargspec
else:
getargspec = inspect.getargspec
class Locked(Exception):
pass
@ -111,4 +106,4 @@ class CoordinationTestCase(test.TestCase):
bar.__getitem__.return_value = 8
func(foo, bar)
get_lock.assert_called_with('lock-func-7-8')
self.assertEqual(['foo', 'bar'], getargspec(func)[0])
self.assertEqual(['foo', 'bar'], inspect.getfullargspec(func)[0])

View File

@ -27,11 +27,6 @@ from cinder.volume.flows.api import manage_existing
from cinder.volume.flows import common as flow_common
from cinder.volume.flows.manager import manage_existing as manager
if hasattr(inspect, 'getfullargspec'):
getargspec = inspect.getfullargspec
else:
getargspec = inspect.getargspec
class ManageVolumeFlowTestCase(test.TestCase):
@ -270,10 +265,10 @@ class ManageVolumeFlowTestCase(test.TestCase):
for p in task.default_provides:
provides.add(p)
execute_args = getargspec(task.execute)[0]
execute_args = inspect.getfullargspec(task.execute)[0]
execute_args = [x for x in execute_args if x not in provides]
[self.assertIn(arg, param_names) for arg in execute_args]
revert_args = getargspec(task.revert)[0]
revert_args = inspect.getfullargspec(task.revert)[0]
revert_args = [x for x in revert_args if x not in revert_provides]
[self.assertIn(arg, param_names) for arg in revert_args]