On this page
  1. ast.compare
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

from ast import compare
help(compare)

Linked from

Related notes