Skip to content

Commit

Permalink
Optimize some if statements for tersity
Browse files Browse the repository at this point in the history
The optimizations are done for tersity, hopefully maintaining readability.
  • Loading branch information
amn committed Sep 29, 2024
1 parent b930beb commit 29a482e
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/csspring/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ def parse_any_value(input: TokenStream) -> Product | None:
case None:
break
result.append(token)
if result:
return result
else:
return None
return result or None

@parse.register
def _(production: CommaSeparatedRepetitionProduction, input: TokenStream) -> Product | None:
Expand Down Expand Up @@ -107,10 +104,7 @@ def _(production: ConcatenationProduction, input: TokenStream) -> Product | None
def _(production: NonEmptyProduction, input: TokenStream) -> Product | None:
"""Variant of `parse` for productions of the `!` multiplier variety (see https://drafts.csswg.org/css-values-4/#mult-req)."""
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`
if result and any(tokens(result)):
return result
else:
return None
return result if result and any(tokens(result)) else None

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

0 comments on commit 29a482e

Please sign in to comment.