all Python 3until 3.11Removed from the standard libraryfunction
inspect.formatargspec()
removed
Built a string like (a, b=1) from the result of getargspec(). Removed in Python 3.11; use str(inspect.signature(f)).
Syntax
inspect.formatargspec(args, varargs=None, varkw=None, defaults=None) # до 3.11
The function took the parts of a parsed signature (args, varargs, varkw, defaults, and so on) and printed them as a parameter list in parentheses. Since Python 3.3 the inspect.Signature object does this: str(signature) already gives the finished string, with annotations and keyword-only parameters. formatargspec() was deprecated in 3.5 and removed in 3.11. How to rewrite: inspect.formatargspec(*inspect.getfullargspec(f)) becomes str(inspect.signature(f)). For a custom signature build an inspect.Signature from a list of inspect.Parameter.
Examples
# Python 3.11+
import inspect
try:
inspect.formatargspec
except AttributeError as e:
print(type(e).__name__) # → AttributeError
# Python 3.11+
import inspect
def f(a, b=1, *, c):
pass
print(inspect.signature(f)) # → (a, b=1, *, c)
P = inspect.Parameter
sig = inspect.Signature([P('x', P.POSITIONAL_OR_KEYWORD, default=0)])
print(sig) # → (x=0)
import inspect
def f(a, b=1, *args):
pass
print(inspect.formatargspec(*inspect.getfullargspec(f))) # → (a, b=1, *args)
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy