Skip to content

Use inspect.signature instead of the deprecated getargspec

Juan Miguel Carceller requested to merge jcarcell/Gaudi:inspect into master

It's removed in Python 3.11 so QMTTest.py will stop working when using that version.

Output comparison, python 2:

from inspect import getargspec

def my_function(arg1, arg2, arg3=None, *args, **kwargs):
    pass

argspec = getargspec(my_function)
print(argspec) # ['arg1', 'arg2', 'arg3']

Python 3:

import inspect

def my_function(arg1, arg2, arg3=None, *args, **kwargs):
    pass

args_order = [param.name for param in inspect.signature(my_function).parameters.values()
                        if param.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD]
print(args_order) # ['arg1', 'arg2', 'arg3']
Edited by Juan Miguel Carceller

Merge request reports

Loading