From b26da16316da46e4770d589ed5f8d404531a22af Mon Sep 17 00:00:00 2001 From: Alex <100605452+Likio3000@users.noreply.github.com> Date: Wed, 23 Sep 2026 07:47:57 +1000 Subject: [PATCH] docs: distinguish tree positions from prefixes (#245) --- AUTHORS.txt | 1 + parso/tree.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 9737530..451918f 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -7,6 +7,7 @@ Code Contributors ================= Alisdair Robertson (@robodair) Bryan Forbes (@bryanforbes) +Likio3000 (@Likio3000) — documentation Code Contributors (to Jedi and therefore possibly to this library) diff --git a/parso/tree.py b/parso/tree.py index 1b2b118..4929496 100644 --- a/parso/tree.py +++ b/parso/tree.py @@ -131,7 +131,8 @@ class NodeOrLeaf: @abstractproperty def start_pos(self) -> Tuple[int, int]: """ - Returns the starting position of the prefix as a tuple, e.g. `(3, 4)`. + Returns the starting position of this node or leaf, excluding its + prefix, as a tuple, e.g. `(3, 4)`. :return tuple of int: (line, column) """ @@ -139,7 +140,8 @@ class NodeOrLeaf: @abstractproperty def end_pos(self) -> Tuple[int, int]: """ - Returns the end position of the prefix as a tuple, e.g. `(3, 4)`. + Returns the position immediately after this node or leaf as a tuple, + e.g. `(3, 4)`. :return tuple of int: (line, column) """ @@ -147,10 +149,10 @@ class NodeOrLeaf: @abstractmethod def get_start_pos_of_prefix(self): """ - Returns the start_pos of the prefix. This means basically it returns - the end_pos of the last prefix. The `get_start_pos_of_prefix()` of the - prefix `+` in `2 + 1` would be `(1, 1)`, while the start_pos is - `(1, 2)`. + Returns the starting position of the prefix (whitespace and comments). + For a leaf with a previous leaf, this is the previous leaf's end_pos. + For example, the `+` leaf in `2 + 1` has a prefix starting at `(1, 1)`, + while its start_pos is `(1, 2)`. :return tuple of int: (line, column) """ @@ -172,8 +174,9 @@ class NodeOrLeaf: """ Returns the code that was the input for the parser for this node. - :param include_prefix: Removes the prefix (whitespace and comments) of - e.g. a statement. + :param bool include_prefix: Include the leading prefix (whitespace and + comments) of this node or leaf. If False, omit only that prefix; + prefixes within a node are preserved. """ def search_ancestor(self, *node_types: str) -> 'Optional[BaseNode]':