Instagram / Instagram/LibCST

[low-pri][doc] Add document to explain the design differences between libcst and ast

Open
#77 0 comments 0 reactions 0 assignees View on GitHub
documentation
Dominant language
Python
Stars
1.9k
Forks
229
PR merge metrics
No merged PRs in 30d

Description

`ast` and libcst looks similar but different in many design details. To make it more clear and prevent confusion for users familiar with ast (I'm one of them), it worth documents the differences with some paragraphs.

| Item with Difference | LibCST | ast |
|---|---|---|
| string value (e.g. asname in Import/ImportFrom) | Name | str |
| Name | `value` | `id` |
| FunctionDef | FunctionDef | FunctionDef and AsyncFunctionDef |
| decorators in ClassDef | `decorators` | `decorator_list` |
| access statement inside for or while loop | `For.body.body[0].body.value` (For.body is an IndentBlock, For.body.body[0] is a SimpleStatementLine, For.body.body[0].body[0] is a Expr.) | `For.body[0].value` (body[0] is an Expr) |
| Call.args | `Sequence[Arg]`, Arg.value stores the value | `Sequence[value]` |
| keyword arg in Call | Arg in Call.args with Arg.keyword is not None | keyword.arg with keyword in Call.keywords |
| ImportFrom.module | Name or Attribute | str or Attribute |

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.