mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-10-31 23:02:40 +00:00
[utils] Improve repr
of DateRange
, match_filter_func
This commit is contained in:
parent
a687226b48
commit
45491a2a30
1 changed files with 10 additions and 0 deletions
|
@ -1379,6 +1379,9 @@ def __contains__(self, date):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'{__name__}.{type(self).__name__}({self.start.isoformat()!r}, {self.end.isoformat()!r})'
|
return f'{__name__}.{type(self).__name__}({self.start.isoformat()!r}, {self.end.isoformat()!r})'
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'{self.start} to {self.end}'
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return (isinstance(other, DateRange)
|
return (isinstance(other, DateRange)
|
||||||
and self.start == other.start and self.end == other.end)
|
and self.start == other.start and self.end == other.end)
|
||||||
|
@ -3239,6 +3242,8 @@ def match_str(filter_str, dct, incomplete=False):
|
||||||
def match_filter_func(filters, breaking_filters=None):
|
def match_filter_func(filters, breaking_filters=None):
|
||||||
if not filters and not breaking_filters:
|
if not filters and not breaking_filters:
|
||||||
return None
|
return None
|
||||||
|
repr_ = f'{match_filter_func.__module__}.{match_filter_func.__qualname__}({filters}, {breaking_filters})'
|
||||||
|
|
||||||
breaking_filters = match_filter_func(breaking_filters) or (lambda _, __: None)
|
breaking_filters = match_filter_func(breaking_filters) or (lambda _, __: None)
|
||||||
filters = set(variadic(filters or []))
|
filters = set(variadic(filters or []))
|
||||||
|
|
||||||
|
@ -3246,6 +3251,7 @@ def match_filter_func(filters, breaking_filters=None):
|
||||||
if interactive:
|
if interactive:
|
||||||
filters.remove('-')
|
filters.remove('-')
|
||||||
|
|
||||||
|
@function_with_repr.set_repr(repr_)
|
||||||
def _match_func(info_dict, incomplete=False):
|
def _match_func(info_dict, incomplete=False):
|
||||||
ret = breaking_filters(info_dict, incomplete)
|
ret = breaking_filters(info_dict, incomplete)
|
||||||
if ret is not None:
|
if ret is not None:
|
||||||
|
@ -4977,6 +4983,10 @@ def __init__(self, func, repr_=None):
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
return self.func(*args, **kwargs)
|
return self.func(*args, **kwargs)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_repr(cls, repr_):
|
||||||
|
return functools.partial(cls, repr_=repr_)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if self.__repr:
|
if self.__repr:
|
||||||
return self.__repr
|
return self.__repr
|
||||||
|
|
Loading…
Reference in a new issue