all Python 3deprecated in 3.9astterm
ast.Param
variables
Deprecated since 3.9: an expression context left over from Python 2, where it marked function parameters; the Python 3 parser never produces it.
Syntax
ast.Param()
In Python 3 parameters are separate arg nodes with no ctx field, so Param never appears in a tree from ast.parse, and compile() rejects one inserted by hand. The class still imports, and code testing isinstance(ctx, ast.Param) silently finds nothing; look for ast.arg instead. It is slated for removal in a future version together with Suite, AugLoad and AugStore.
Examples
import ast
tree = ast.parse('def f(a, b): pass')
params = [n.arg for n in ast.walk(tree) if isinstance(n, ast.arg)]
print(params) # → ['a', 'b']
print(any(isinstance(getattr(n, 'ctx', None), ast.Param) for n in ast.walk(tree))) # → False
import ast
m = ast.parse('x = 1')
m.body[0].targets[0].ctx = ast.Param()
try:
compile(m, '<ast>', 'exec')
except TypeError as e:
print(type(e).__name__) # → TypeError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy