Skip to content

Commit 29a482e

Browse files
committed
Optimize some if statements for tersity
The optimizations are done for tersity, hopefully maintaining readability.
1 parent b930beb commit 29a482e

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/csspring/selectors.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ def parse_any_value(input: TokenStream) -> Product | None:
6262
case None:
6363
break
6464
result.append(token)
65-
if result:
66-
return result
67-
else:
68-
return None
65+
return result or None
6966

7067
@parse.register
7168
def _(production: CommaSeparatedRepetitionProduction, input: TokenStream) -> Product | None:
@@ -107,10 +104,7 @@ def _(production: ConcatenationProduction, input: TokenStream) -> Product | None
107104
def _(production: NonEmptyProduction, input: TokenStream) -> Product | None:
108105
"""Variant of `parse` for productions of the `!` multiplier variety (see https://drafts.csswg.org/css-values-4/#mult-req)."""
109106
result = cast(Product, parse(production.element, input)) # The element of a non-empty production is concatenation, and the `parse` overload for `ConcatenationProduction` never returns a `Token`, only `Product | None`
110-
if result and any(tokens(result)):
111-
return result
112-
else:
113-
return None
107+
return result if result and any(tokens(result)) else None
114108

115109
@parse.register
116110
def _(production: ReferenceProduction, input: TokenStream) -> Product | Token | None:

0 commit comments

Comments
 (0)