mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Rename Token.ref to Token.with_reference, add docstring
This commit is contained in:
@@ -264,7 +264,7 @@ def substitute_references(tokens: Iterator[Token]) -> Iterable[Token]:
|
||||
ref_location = token.location
|
||||
ref_length = cell_len(token.value)
|
||||
for token in reference_tokens:
|
||||
yield token.ref(
|
||||
yield token.with_reference(
|
||||
ReferencedBy(
|
||||
name=ref_name,
|
||||
location=ref_location,
|
||||
@@ -285,7 +285,7 @@ def substitute_references(tokens: Iterator[Token]) -> Iterable[Token]:
|
||||
ref_location = token.location
|
||||
ref_length = cell_len(token.value)
|
||||
for token in variable_tokens:
|
||||
yield token.ref(
|
||||
yield token.with_reference(
|
||||
ReferencedBy(
|
||||
name=variable_name,
|
||||
location=ref_location,
|
||||
|
||||
@@ -54,7 +54,13 @@ class Token(NamedTuple):
|
||||
location: tuple[int, int]
|
||||
referenced_by: ReferencedBy | None
|
||||
|
||||
def ref(self, by: ReferencedBy | None) -> "Token":
|
||||
def with_reference(self, by: ReferencedBy | None) -> "Token":
|
||||
"""Return a copy of the Token, with reference information attached.
|
||||
This is used for variable substitution, where a variable reference
|
||||
can refer to tokens which were defined elsewhere. With the additional
|
||||
ReferencedBy data attached, we can track where the token we are referring
|
||||
to is used.
|
||||
"""
|
||||
return Token(
|
||||
name=self.name,
|
||||
value=self.value,
|
||||
|
||||
Reference in New Issue
Block a user