Expand description
Rendering the Python CST. Spec §5.
One style, PEP 8: four spaces, two blank lines around a top-level class, one around a nested one, and a docstring as the first statement of every class body.
§Indentation is the grammar here
In the other four renderers a wrong indent is untidy output. In Python
it is a different program, or none. So the block structure is the only
thing this file computes: Writer owns the depth, every body goes
through render_body, and nothing else in this module writes a
newline.
§The output is pure ASCII
Every code point outside printable ASCII is escaped, in string literals and in docstrings alike. A generated file that is pure ASCII cannot be changed by an editor, a terminal or a CI runner that guessed the wrong encoding — and a wire test whose expected string arrived mangled would report a byte difference that is really a file-transfer difference.
Functions§
- expr
- Render one expression, for a caller that wants its spelling.
- module
- Render a whole module.
- statement
- Render one statement, for a caller that has only one.
- string_
literal - A double-quoted Python string literal holding
text, in ASCII. - type_
- Render one annotation, for a caller that wants its spelling.