Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

library: debug log parsed queries (and convert to f-strings) #4962

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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