Python Glossary Русский

all Python 3deprecated in 3.9astterm

ast.Suite

root and base nodes

Deprecated since 3.9: a root node left over from Python 2; neither ast.parse nor compile() in Python 3 produces or accepts it.

Syntax

ast.Suite()

A Python 3 tree has four possible roots, picked by the mode argument: Module for 'exec', Expression for 'eval', Interactive for 'single' and FunctionType for 'func_type'. There is no 'suite' mode, and compile(ast.Suite(), …) raises TypeError. The class survives only for compatibility and is slated for removal together with Param, AugLoad and AugStore; new code never uses it.

Examples

import ast
for mode in ('exec', 'eval', 'single'):
    print(type(ast.parse('1', mode=mode)).__name__)  # → Module / Expression / Interactive
import ast
try:
    compile(ast.Suite(), '<ast>', 'exec')
except TypeError as e:
    print(e)  # → expected Module node, got Suite

See also

Open in the full glossarydocs.python.orgReport an inaccuracy