From 733fbb902a0a09d967dff83e62b6e8732f4980c2 Mon Sep 17 00:00:00 2001 From: Moritz Neeb Date: Sat, 22 Jul 2023 12:24:03 +0200 Subject: [PATCH] refactor: simplify css variable table creation --- src/textual/css/parse.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/textual/css/parse.py b/src/textual/css/parse.py index a604fed01e1..1b31e8b66b0 100644 --- a/src/textual/css/parse.py +++ b/src/textual/css/parse.py @@ -269,6 +269,7 @@ def substitute_references( break if token.name == "variable_name": variable_name = token.value[1:-1] # Trim the $ and the :, i.e. "$x:" -> "x" + variable_tokens = variables.setdefault(variable_name, []) yield token while True: @@ -284,18 +285,15 @@ def substitute_references( if not token: break elif token.name == "whitespace": - variables.setdefault(variable_name, []).append(token) + variable_tokens.append(token) yield token elif token.name == "variable_value_end": - # in case of an empty variable, avoid not referenced error - variables.setdefault(variable_name, []) yield token break # For variables referring to other variables elif token.name == "variable_ref": ref_name = token.value[1:] if ref_name in variables: - variable_tokens = variables.setdefault(variable_name, []) reference_tokens = variables[ref_name] variable_tokens.extend(reference_tokens) ref_location = token.location @@ -309,7 +307,7 @@ def substitute_references( else: _unresolved(ref_name, variables.keys(), token) else: - variables.setdefault(variable_name, []).append(token) + variable_tokens.append(token) yield token token = next(iter_tokens, None) elif token.name == "variable_ref":