mirror of
https://github.com/beetbox/beets.git
synced 2025-12-14 20:43:41 +01:00
Fix and mark errors
This commit is contained in:
parent
13c1561390
commit
3f8afb9a45
3 changed files with 22 additions and 13 deletions
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
import re
|
||||
from operator import mul
|
||||
from typing import Union, Tuple, List, Optional, Pattern, Any, Type, Iterator, \
|
||||
Collection, Mapping, MutableMapping
|
||||
from typing import Union, Tuple, List, Optional, Pattern, Any, Type, Iterator,\
|
||||
Collection, Mapping, MutableMapping, Sequence
|
||||
|
||||
from beets import util
|
||||
from datetime import datetime, timedelta
|
||||
|
|
@ -66,7 +66,7 @@ class Query:
|
|||
"""An abstract class representing a query into the item database.
|
||||
"""
|
||||
|
||||
def clause(self) -> Union[None, Tuple]:
|
||||
def clause(self) -> Tuple[None, Tuple]:
|
||||
"""Generate an SQLite expression implementing the query.
|
||||
|
||||
Return (clause, subvals) where clause is a valid sqlite
|
||||
|
|
@ -375,7 +375,7 @@ class CollectionQuery(Query):
|
|||
indexed like a list to access the sub-queries.
|
||||
"""
|
||||
|
||||
def __init__(self, subqueries: Mapping = ()):
|
||||
def __init__(self, subqueries: Sequence = ()):
|
||||
self.subqueries = subqueries
|
||||
|
||||
# Act like a sequence.
|
||||
|
|
@ -439,6 +439,7 @@ class AnyFieldQuery(CollectionQuery):
|
|||
subqueries = []
|
||||
for field in self.fields:
|
||||
subqueries.append(cls(field, pattern, True))
|
||||
# TYPING ERROR
|
||||
super().__init__(subqueries)
|
||||
|
||||
def clause(self) -> Tuple[str | None, Collection]:
|
||||
|
|
@ -488,7 +489,7 @@ class AndQuery(MutableCollectionQuery):
|
|||
class OrQuery(MutableCollectionQuery):
|
||||
"""A conjunction of a list of other queries."""
|
||||
|
||||
def clause(self) -> Tuple[str | None, Collection]:
|
||||
def clause(self) -> Tuple[Union[str, None], Collection]:
|
||||
return self.clause_with_joiner('or')
|
||||
|
||||
def match(self, item) -> bool:
|
||||
|
|
@ -845,6 +846,7 @@ class MultipleSort(Sort):
|
|||
order = sort.order_clause()
|
||||
order_strings.append(order)
|
||||
|
||||
# TYPING ERROR
|
||||
return ", ".join(order_strings)
|
||||
|
||||
def is_slow(self) -> bool:
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@
|
|||
|
||||
import re
|
||||
import itertools
|
||||
from typing import Dict, Type, Tuple, Optional, Mapping, Collection, List
|
||||
from typing import Dict, Type, Tuple, Optional, Mapping, Collection, List, \
|
||||
Sequence
|
||||
|
||||
from . import query, Model
|
||||
from .query import Sort
|
||||
|
|
@ -37,6 +38,8 @@ PARSE_QUERY_PART_REGEX = re.compile(
|
|||
)
|
||||
|
||||
|
||||
# TYPING ERROR
|
||||
# not sure what the query type should be
|
||||
def parse_query_part(
|
||||
part: str,
|
||||
query_classes: Dict = {},
|
||||
|
|
@ -109,7 +112,7 @@ def parse_query_part(
|
|||
|
||||
def construct_query_part(
|
||||
model_cls: Type[Model],
|
||||
prefixes: Mapping[str, Type[query.Query]],
|
||||
prefixes: Dict,
|
||||
query_part: str,
|
||||
) -> query.Query:
|
||||
"""Parse a *query part* string and return a :class:`Query` object.
|
||||
|
|
@ -169,10 +172,11 @@ def construct_query_part(
|
|||
return out_query
|
||||
|
||||
|
||||
# TYPING ERROR
|
||||
def query_from_strings(
|
||||
query_cls: Type[query.Query],
|
||||
model_cls: Type[Model],
|
||||
prefixes: Mapping[str, Type[query.Query]],
|
||||
prefixes: Dict,
|
||||
query_parts: Collection[str],
|
||||
) -> query.Query:
|
||||
"""Creates a collection query of type `query_cls` from a list of
|
||||
|
|
@ -219,7 +223,7 @@ def construct_sort_part(
|
|||
|
||||
def sort_from_strings(
|
||||
model_cls: Type[Model],
|
||||
sort_parts: Collection[str],
|
||||
sort_parts: Sequence[str],
|
||||
case_insensitive: bool = True,
|
||||
) -> Sort:
|
||||
"""Create a `Sort` from a list of sort criteria (strings).
|
||||
|
|
@ -239,7 +243,7 @@ def sort_from_strings(
|
|||
def parse_sorted_query(
|
||||
model_cls: Type[Model],
|
||||
parts: List[str],
|
||||
prefixes: Mapping[str, Type[query.Query]] = {},
|
||||
prefixes: Dict = {},
|
||||
case_insensitive: bool = True,
|
||||
) -> Tuple[query.Query, Sort]:
|
||||
"""Given a list of strings, create the `Query` and `Sort` that they
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
"""
|
||||
|
||||
from typing import Union, Any
|
||||
from typing import Type as TypingType
|
||||
from . import query
|
||||
from beets.util import str2bool
|
||||
|
||||
|
|
@ -50,7 +51,7 @@ class Type:
|
|||
"""
|
||||
return self.model_type()
|
||||
|
||||
def format(self, value: model_type) -> str:
|
||||
def format(self, value: TypingType[model_type]) -> str:
|
||||
"""Given a value of this type, produce a Unicode string
|
||||
representing the value. This is used in template evaluation.
|
||||
"""
|
||||
|
|
@ -73,11 +74,12 @@ class Type:
|
|||
except ValueError:
|
||||
return self.null
|
||||
|
||||
def normalize(self, value: model_type) -> model_type:
|
||||
def normalize(self, value: TypingType[model_type]) -> model_type:
|
||||
"""Given a value that will be assigned into a field of this
|
||||
type, normalize the value to have the appropriate type. This
|
||||
base implementation only reinterprets `None`.
|
||||
"""
|
||||
# TYPING ERROR
|
||||
if value is None:
|
||||
return self.null
|
||||
else:
|
||||
|
|
@ -107,6 +109,7 @@ class Type:
|
|||
if isinstance(sql_value, str):
|
||||
return self.parse(sql_value)
|
||||
else:
|
||||
# TYPING ERROR
|
||||
return self.normalize(sql_value)
|
||||
|
||||
def to_sql(self, model_value: Any) -> Union[None, int, float, str, bytes]:
|
||||
|
|
@ -129,7 +132,7 @@ class Integer(Type):
|
|||
query = query.NumericQuery
|
||||
model_type = int
|
||||
|
||||
def normalize(self, value) -> Union[int, str]:
|
||||
def normalize(self, value: str) -> Union[int, str]:
|
||||
try:
|
||||
return self.model_type(round(float(value)))
|
||||
except ValueError:
|
||||
|
|
|
|||
Loading…
Reference in a new issue