From 75a2e5f579490271dd947937a76410ade3c8a185 Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Mon, 7 Feb 2022 11:47:16 +0000 Subject: [PATCH] Rename `Token.ref` to `Token.with_reference`, add docstring --- src/textual/css/parse.py | 4 ++-- src/textual/css/tokenizer.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/textual/css/parse.py b/src/textual/css/parse.py index bb6db0b82..955f19762 100644 --- a/src/textual/css/parse.py +++ b/src/textual/css/parse.py @@ -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, diff --git a/src/textual/css/tokenizer.py b/src/textual/css/tokenizer.py index 8daf4128c..e0910f43b 100644 --- a/src/textual/css/tokenizer.py +++ b/src/textual/css/tokenizer.py @@ -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,