diff options
author | Simon Sawicki <contact@grub4k.xyz> | 2023-04-24 19:56:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-24 19:56:35 +0200 |
commit | 21b5ec86c2c37d10c5bb97edd7051d3aac16bb3e (patch) | |
tree | 28515276d2458b18e19beb8cc86cf536855820b6 /yt_dlp/utils.py | |
parent | c16644642b08e2bf4130a6c5fa01395d8718c990 (diff) | |
download | hypervideo-pre-21b5ec86c2c37d10c5bb97edd7051d3aac16bb3e.tar.lz hypervideo-pre-21b5ec86c2c37d10c5bb97edd7051d3aac16bb3e.tar.xz hypervideo-pre-21b5ec86c2c37d10c5bb97edd7051d3aac16bb3e.zip |
[utils] `traverse_obj`: Allow iterables in traversal (#6902)
Authored by: Grub4K
Diffstat (limited to 'yt_dlp/utils.py')
-rw-r--r-- | yt_dlp/utils.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index 746a2885d..f69311462 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -5528,7 +5528,6 @@ def traverse_obj( If no `default` is given and the last path branches, a `list` of results is always returned. If a path ends on a `dict` that result will always be a `dict`. """ - is_sequence = lambda x: isinstance(x, collections.abc.Sequence) and not isinstance(x, (str, bytes)) casefold = lambda k: k.casefold() if isinstance(k, str) else k if isinstance(expected_type, type): @@ -5564,7 +5563,7 @@ def traverse_obj( branching = True if isinstance(obj, collections.abc.Mapping): result = obj.values() - elif is_sequence(obj): + elif isinstance(obj, collections.abc.Iterable) and not isinstance(obj, (str, bytes)): result = obj elif isinstance(obj, re.Match): result = obj.groups() @@ -5578,7 +5577,7 @@ def traverse_obj( branching = True if isinstance(obj, collections.abc.Mapping): iter_obj = obj.items() - elif is_sequence(obj): + elif isinstance(obj, collections.abc.Iterable) and not isinstance(obj, (str, bytes)): iter_obj = enumerate(obj) elif isinstance(obj, re.Match): iter_obj = itertools.chain( @@ -5614,7 +5613,7 @@ def traverse_obj( result = next((v for k, v in obj.groupdict().items() if casefold(k) == key), None) elif isinstance(key, (int, slice)): - if is_sequence(obj): + if isinstance(obj, collections.abc.Sequence) and not isinstance(obj, (str, bytes)): branching = isinstance(key, slice) with contextlib.suppress(IndexError): result = obj[key] |