Skip to content

Python editor source formatting

This page describes the Python authoring surface, not the declarative .strat language in Strategy sections. Python block bodies require physical newlines and indentation. Four spaces per level are the normal convention; preserve existing consistent indentation and do not mix tabs with spaces.

def on_tick():
    if not position:
        buy(10)

For an inline editor completion after def on_tick():, the inserted body begins with an actual newline followed by four spaces. After if not position:, the next body line begins with a newline and eight spaces. Spaces alone after a complete statement are not a new line. If the cursor already sits after a newline and indentation, do not insert that indentation twice. Completion inside an identifier, string, function argument or unfinished expression must preserve the surrounding expression instead of forcing a new statement. A literal \n in a Python string represents a character in that string, not source-line structure.

Completion text is only the missing gap, not a replacement for the entire line. For example, rsi(cl followed by ose, 14) must remain rsi(close, 14), not two statements. Subsequent inserted lines still need their complete indentation. An editor must preserve newline characters in the returned insertion string; joining lines with spaces changes Python scope and can make the source invalid.