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

File objects with no tags cast to boolean as false #577

Open
sparr opened this issue Sep 9, 2022 · 0 comments
Open

File objects with no tags cast to boolean as false #577

sparr opened this issue Sep 9, 2022 · 0 comments
Assignees

Comments

@sparr
Copy link

sparr commented Sep 9, 2022

True if mutagen.File("foo.ogg") else False

This will evaluate to False if foo.ogg contains no id3 tags. I believe this is because the mutagen file types do not have a __bool__ method, so the implicit boolean cast falls back on __len__ which ends up referring to the number of keys in the DictProxy for the file's id3 tags.

While I could work around this by explicitly checking for None vs a file type instance, I think it would be reasonable to expect the type to cast to True when it has successfully loaded a file.

@phw phw self-assigned this Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants