Skip to content

Commit

Permalink
[utils] Improve repr of DateRange, match_filter_func
Browse files Browse the repository at this point in the history
  • Loading branch information
pukkandan committed Mar 10, 2024
1 parent a687226 commit 45491a2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions yt_dlp/utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,9 @@ def __contains__(self, date):
def __repr__(self):
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):
return (isinstance(other, DateRange)
and self.start == other.start and self.end == other.end)
Expand Down Expand Up @@ -3239,13 +3242,16 @@ def match_str(filter_str, dct, incomplete=False):
def match_filter_func(filters, breaking_filters=None):
if not filters and not breaking_filters:
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)
filters = set(variadic(filters or []))

interactive = '-' in filters
if interactive:
filters.remove('-')

@function_with_repr.set_repr(repr_)
def _match_func(info_dict, incomplete=False):
ret = breaking_filters(info_dict, incomplete)
if ret is not None:
Expand Down Expand Up @@ -4977,6 +4983,10 @@ def __init__(self, func, repr_=None):
def __call__(self, *args, **kwargs):
return self.func(*args, **kwargs)

@classmethod
def set_repr(cls, repr_):
return functools.partial(cls, repr_=repr_)

def __repr__(self):
if self.__repr:
return self.__repr
Expand Down

0 comments on commit 45491a2

Please sign in to comment.