Skip to content

Commit

Permalink
flip logic to guard clause in filter process method
Browse files Browse the repository at this point in the history
  • Loading branch information
geo-martino committed Dec 14, 2024
1 parent 757089b commit 4815d9a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions musify/processors/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ def __call__(self, *args, **kwargs) -> Collection[T]:

def process(self, values: Collection[T] | None = None, *_, **__) -> Collection[T]:
"""Returns all ``values`` that match this filter's settings"""
if self.ready:
matches = [value for value in values if self.transform(value) in self.values]
if isinstance(self.values, Sequence):
matches = sorted((self.values.index(self.transform(match)), match) for match in matches)
return [match[1] for match in matches]
return matches
return values
if not self.ready:
return values

matches = [value for value in values if self.transform(value) in self.values]
if isinstance(self.values, Sequence):
matches = sorted((self.values.index(self.transform(match)), match) for match in matches)
return [match[1] for match in matches]
return matches

def as_dict(self) -> dict[str, Any]:
return {"values": self.values}
Expand Down

0 comments on commit 4815d9a

Please sign in to comment.