1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-09-03 00:25:08 +00:00

[utils] traverse_obj: Allow unbranching using all and any (#9571)

Authored by: Grub4K
This commit is contained in:
Simon Sawicki
2024-03-30 19:54:43 +01:00
committed by GitHub
parent 979ce2e786
commit 3699eeb67c
2 changed files with 41 additions and 0 deletions

View File

@ -228,6 +228,15 @@ def traverse_obj(
if not casesense and isinstance(key, str):
key = key.casefold()
if key in (any, all):
has_branched = False
filtered_objs = (obj for obj in objs if obj not in (None, {}))
if key is any:
objs = (next(filtered_objs, None),)
else:
objs = (list(filtered_objs),)
continue
if __debug__ and callable(key):
# Verify function signature
inspect.signature(key).bind(None, None)