Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[utils] traverse_obj: return [] if last path branches without default #5170

Merged
merged 4 commits into from Oct 9, 2022

Conversation

Grub4K
Copy link
Member

@Grub4K Grub4K commented Oct 7, 2022

IMPORTANT: PRs without the template will be CLOSED

Description of your pull request and other information

It is common to see a pattern like traverse_obj(obj, ...) or [] since the default is currently None.
This can cause developers to fall into the trap of doing for item in traverse_obj(obj, ...).
This PR addresses this issue by defaulting to [] if the last path did not match and no default was provided.

Template

Before submitting a pull request make sure you have:

In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under Unlicense. Check one of the following options:

  • I am the original author of this code and I am willing to release it under Unlicense
  • I am not the original author of this code but it is in public domain or released under Unlicense (provide reliable evidence)

What is the purpose of your pull request?

Closes #5162

yt_dlp/utils.py Outdated Show resolved Hide resolved
yt_dlp/utils.py Outdated Show resolved Hide resolved
yt_dlp/utils.py Outdated Show resolved Hide resolved
@pukkandan pukkandan merged commit f99bbfc into yt-dlp:master Oct 9, 2022
@Grub4K Grub4K deleted the traverse-obj-branching-list-default branch October 9, 2022 03:10
dirkf added a commit to dirkf/youtube-dl that referenced this pull request May 3, 2023
Thanks Grub4k for these:
* traverse `Iterable`s, from yt-dlp/yt-dlp#6902, etc
* traverse `set` key for transformations/filters, `re.Match` group names, from
  yt-dlp/yt-dlp@776995b, etc
* traverse `re.Match`es, from yt-dlp/yt-dlp#5174
* always return list when branching, from yt-dlp/yt-dlp#5170
dirkf added a commit to dirkf/youtube-dl that referenced this pull request Jul 18, 2023
Thanks Grub4k for these:
* traverse `Iterable`s, from yt-dlp/yt-dlp#6902, etc
* traverse `set` key for transformations/filters, `re.Match` group names, from
  yt-dlp/yt-dlp@776995b, etc
* traverse `re.Match`es, from yt-dlp/yt-dlp#5174
* always return list when branching, from yt-dlp/yt-dlp#5170
dirkf added a commit to ytdl-org/youtube-dl that referenced this pull request Jul 19, 2023
Thanks Grub4k for these:
* traverse `Iterable`s, from yt-dlp/yt-dlp#6902, etc
* traverse `set` key for transformations/filters, `re.Match` group names, from
  yt-dlp/yt-dlp@776995b, etc
* traverse `re.Match`es, from yt-dlp/yt-dlp#5174
* always return list when branching, from yt-dlp/yt-dlp#5170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants