Skip to content

Commit

Permalink
Merge pull request #4962 from wisp3rwind/log_parsed_query
Browse files Browse the repository at this point in the history
library: debug log parsed queries (and convert to f-strings)
  • Loading branch information
wisp3rwind authored Oct 22, 2023
2 parents 2115369 + 979e71d commit a091f31
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
26 changes: 14 additions & 12 deletions beets/dbcore/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def match(self, obj: Model) -> bool:

def __repr__(self) -> str:
return (
"{0.__class__.__name__}({0.field!r}, {0.pattern!r}, "
"{0.fast})".format(self)
f"{self.__class__.__name__}({self.field!r}, {self.pattern!r}, "
f"fast={self.fast})"
)

def __eq__(self, other) -> bool:
Expand Down Expand Up @@ -205,7 +205,7 @@ def match(self, obj: Model) -> bool:
return obj.get(self.field) is None

def __repr__(self) -> str:
return "{0.__class__.__name__}({0.field!r}, {0.fast})".format(self)
return f"{self.__class__.__name__}({self.field!r}, {self.fast})"


class StringFieldQuery(FieldQuery[P]):
Expand Down Expand Up @@ -471,7 +471,7 @@ def clause_with_joiner(
return clause, subvals

def __repr__(self) -> str:
return "{0.__class__.__name__}({0.subqueries!r})".format(self)
return f"{self.__class__.__name__}({self.subqueries!r})"

def __eq__(self, other) -> bool:
return super().__eq__(other) and self.subqueries == other.subqueries
Expand Down Expand Up @@ -511,8 +511,8 @@ def match(self, obj: Model) -> bool:

def __repr__(self) -> str:
return (
"{0.__class__.__name__}({0.pattern!r}, {0.fields!r}, "
"{0.query_class.__name__})".format(self)
f"{self.__class__.__name__}({self.pattern!r}, {self.fields!r}, "
f"{self.query_class.__name__})"
)

def __eq__(self, other) -> bool:
Expand Down Expand Up @@ -577,7 +577,7 @@ def match(self, obj: Model) -> bool:
return not self.subquery.match(obj)

def __repr__(self) -> str:
return "{0.__class__.__name__}({0.subquery!r})".format(self)
return f"{self.__class__.__name__}({self.subquery!r})"

def __eq__(self, other) -> bool:
return super().__eq__(other) and self.subquery == other.subquery
Expand Down Expand Up @@ -883,6 +883,9 @@ def __hash__(self) -> int:
def __eq__(self, other) -> bool:
return type(self) is type(other)

def __repr__(self):
return f"{self.__class__.__name__}()"


class MultipleSort(Sort):
"""Sort that encapsulates multiple sub-sorts."""
Expand Down Expand Up @@ -934,7 +937,7 @@ def sort(self, items):
return items

def __repr__(self):
return f"MultipleSort({self.sorts!r})"
return f"{self.__class__.__name__}({self.sorts!r})"

def __hash__(self):
return hash(tuple(self.sorts))
Expand Down Expand Up @@ -972,10 +975,9 @@ def key(obj: Model) -> Any:
return sorted(objs, key=key, reverse=not self.ascending)

def __repr__(self) -> str:
return "<{}: {}{}>".format(
type(self).__name__,
self.field,
"+" if self.ascending else "-",
return (
f"{self.__class__.__name__}"
f"({self.field!r}, ascending={self.ascending!r})"
)

def __hash__(self) -> int:
Expand Down
5 changes: 4 additions & 1 deletion beets/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,9 +1518,12 @@ def parse_query_parts(parts, model_cls):

case_insensitive = beets.config["sort_case_insensitive"].get(bool)

return dbcore.parse_sorted_query(
query, sort = dbcore.parse_sorted_query(
model_cls, parts, prefixes, case_insensitive
)
log.debug("Parsed query: {!r}", query)
log.debug("Parsed sort: {!r}", sort)
return query, sort


def parse_query_string(s, model_cls):
Expand Down

0 comments on commit a091f31

Please sign in to comment.