docs: distinguish tree positions from prefixes (#245)
Build / lint (push) Canceled after 0s
Build / test (false, 3.10) (push) Canceled after 0s
Build / test (false, 3.11) (push) Canceled after 0s
Build / test (false, 3.12) (push) Canceled after 0s
Build / test (false, 3.13) (push) Canceled after 0s
Build / test (false, 3.8) (push) Canceled after 0s
Build / test (false, 3.9) (push) Canceled after 0s
Build / coverage (push) Canceled after 0s

This commit is contained in:
Alex
2026-09-22 21:47:57 +00:00
committed by GitHub
parent 7f5b142b54
commit b26da16316
2 changed files with 12 additions and 8 deletions
+1
View File
@@ -7,6 +7,7 @@ Code Contributors
=================
Alisdair Robertson (@robodair)
Bryan Forbes (@bryanforbes) <bryan@reigndropsfall.net>
Likio3000 (@Likio3000) — documentation
Code Contributors (to Jedi and therefore possibly to this library)
+11 -8
View File
@@ -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]':