Skip to content

Commit 02f1404

Browse files
committed
🟢
1 parent 7af5c50 commit 02f1404

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

Diff for: ‎src/napari_matplotlib/util.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List, Optional, Tuple, Union
1+
from typing import List, Optional, Tuple, Union, Generator
22
from warnings import warn
33

44
import napari.qt
@@ -41,6 +41,22 @@ def __contains__(self, val: int) -> bool:
4141
return True
4242

4343

44+
def _logical_lines(
45+
nodes: List[tinycss2.ast.Node],
46+
) -> Generator[Tuple[tinycss2.ast.Node, tinycss2.ast.Node], None, None]:
47+
"""Generator to provide logical lines (thing: value) of css (terminated by ';')"""
48+
logical_line = []
49+
ident, dimension = None, None
50+
for node in nodes:
51+
if node == ";":
52+
yield (ident, dimension)
53+
ident, dimension = None, None
54+
elif node.type == "ident":
55+
ident = node
56+
elif node.type == "dimension":
57+
dimension = node
58+
59+
4460
def _has_id(nodes: List[tinycss2.ast.Node], id_name: str) -> bool:
4561
"""
4662
Is `id_name` in IdentTokens in the list of CSS `nodes`?
@@ -61,12 +77,8 @@ def _get_dimension(
6177
None if no IdentToken is found.
6278
"""
6379
cleaned_nodes = [node for node in nodes if node.type != "whitespace"]
64-
for name, _, value, _ in zip(*(iter(cleaned_nodes),) * 4):
65-
if (
66-
name.type == "ident"
67-
and value.type == "dimension"
68-
and name.value == id_name
69-
):
80+
for name, value in _logical_lines(cleaned_nodes):
81+
if name.value == id_name:
7082
return value.int_value
7183
warn(f"Unable to find DimensionToken for {id_name}", RuntimeWarning)
7284
return None

0 commit comments

Comments
 (0)