From 45491a2a30da4d1723cfa9288cb664813bb09afb Mon Sep 17 00:00:00 2001 From: pukkandan Date: Wed, 31 Jan 2024 15:57:37 +0530 Subject: [PATCH] [utils] Improve `repr` of `DateRange`, `match_filter_func` --- yt_dlp/utils/_utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index 49944e9d2..9efeb6a1c 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -1379,6 +1379,9 @@ class DateRange: 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) @@ -3239,6 +3242,8 @@ 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 [])) @@ -3246,6 +3251,7 @@ def match_filter_func(filters, breaking_filters=None): 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: @@ -4977,6 +4983,10 @@ class function_with_repr: 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