summaryrefslogtreecommitdiffstats
path: root/Lib/_pyrepl
diff options
context:
space:
mode:
authorBatuhan Taskaya <isidentical@gmail.com>2024-05-22 01:39:26 (GMT)
committerGitHub <noreply@github.com>2024-05-22 01:39:26 (GMT)
commitd065edfb66470bbf06367b3570661d0346aa6707 (patch)
treeb05bef2dcc06a4302a6e63627b36c5c90b2b6f0e /Lib/_pyrepl
parent0e3c8cda1f04c983994e76aea93600dbb4714832 (diff)
downloadcpython-d065edfb66470bbf06367b3570661d0346aa6707.zip
cpython-d065edfb66470bbf06367b3570661d0346aa6707.tar.gz
cpython-d065edfb66470bbf06367b3570661d0346aa6707.tar.bz2
gh-60191: Implement ast.compare (#19211)
* bpo-15987: Implement ast.compare Add a compare() function that compares two ASTs for structural equality. There are two set of attributes on AST node objects, fields and attributes. The fields are always compared, since they represent the actual structure of the code. The attributes can be optionally be included in the comparison. Attributes capture things like line numbers of column offsets, so comparing them involves test whether the layout of the program text is the same. Since whitespace seems inessential for comparing ASTs, the default is to compare fields but not attributes. ASTs are just Python objects that can be modified in arbitrary ways. The API for ASTs is under-specified in the presence of user modifications to objects. The comparison respects modifications to fields and attributes, and to _fields and _attributes attributes. A user could create obviously malformed objects, and the code will probably fail with an AttributeError when that happens. (For example, adding "spam" to _fields but not adding a "spam" attribute to the object.) Co-authored-by: Jeremy Hylton <jeremy@alum.mit.edu>
Diffstat (limited to 'Lib/_pyrepl')
0 files changed, 0 insertions, 0 deletions