Skip to content

Commit 1b79b9b

Browse files
committed
Fix a critical values.Formatter issue
The formatting implemented by the class was in part broken since it raised `TypeError` exceptions even for token productions that are part of the `selectors.grammar` object. This commits implements the omitted functionality, fixing the issue.
1 parent dce2374 commit 1b79b9b

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/csspring/values.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
33
Only parts currently in use by the rest of the `csspring` pcakge, are implemented.
44
"""
5-
from .syntax.tokenizing import Token, CommaToken, CommentToken, WhitespaceToken
6-
from .syntax.tokenizing import ColonToken
5+
from .syntax.tokenizing import Token, token_value, CommaToken, CommentToken, WhitespaceToken
76

87
import builtins
98
from collections.abc import Iterable, Mapping
@@ -182,11 +181,7 @@ def _(self, production: TokenProduction) -> Iterable[str]:
182181
if hasattr(production.type, 'value'):
183182
yield '<' + re.sub(r'(^)?[A-Z]', lambda m: (('-' if m[1] is None else '') + m[0].lower()), production.type.__name__) + '>' # type: ignore # MyPy 1.11 complains with "error: Unsupported operand types for + ("str" and "bytes") [operator]", but the error appears to be a false positive: http://github.com/python/mypy/issues/12961 # TODO: Revisit the issue following MyPy updates
184183
else:
185-
if issubclass(production.type, ColonToken):
186-
value = ','
187-
else:
188-
raise TypeError
189-
yield repr(value)
184+
yield repr(token_value(production.type))
190185
@format.register
191186
def _(self, production: CommaSeparatedRepetitionProduction) -> Iterable[str]:
192187
yield from self.operand(production.element)

0 commit comments

Comments
 (0)