On this page
ast.compare
Prev: ast.BitOr | Up: ast | Next: ast.copy_location
Rel: ast.Add, ast.alias, ast.And, ast.AnnAssign
Ref: docs.python.org — ast.compare
Tags: #public #python3 #stdlib #ast
Import
import ast
from ast import compare
Signature & Overview
ast.compare(a, b, /, *, compare_attributes=False)
Recursively compares two ASTs.
Usage
import ast
# Python 3.14+: structural equality check between two ASTs
assert ast.compare(ast.parse("x = 1"), ast.parse("x = 1")) is True
Gotchas
- Requires Python 3.14+: On older Python, compare
ast.dump(t1) == ast.dump(t2)instead.
REPL Inspect
from ast import compare
help(compare)
Linked from
Related notes
- tuts/python3/stdlib_module/ast/BitOr Linked here; links to this page; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/copy_location Linked here; links to this page; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/Add Linked here; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/alias Linked here; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/And Linked here; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/AnnAssign Linked here; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/AST Linked here; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ast/arg shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/arguments shared tags: #ast, #stdlib