Skip to content

SoundFile objects logically evaluate to False #199

@tgarc

Description

@tgarc

I noticed that SoundFile objects always evaluate to False. For example:

wf = sf.SoundFile('input.wav')
if wf:
    print("cool wav file man!")
    # never executed
else:
    print("no wav file...not cool.")

I don't know where this is coming from, I think by default classes inheriting from object will evaluate to True. Is this intended behavior? It's often convenient to rely on the object logically evaluating to True; for one thing builtin file objects evaluate to True so I would expect this behavior from SoundFile as well. Would you be alright with adding a bool method to return True?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions