Skip to content

Conversation

@mgeier
Copy link
Member

@mgeier mgeier commented Jan 22, 2026

Pure input/output streams only use one of data/out respectively, so we have to take care whether they even exist before we delete them.

Fixes #621.

@jared-v-hoyt
Copy link

jared-v-hoyt commented Jan 23, 2026

Can we do the same thing with the following?

self.pop("data", None)
self.pop("out", None)

Not sure if there's a need to import contextlib here.

@mgeier
Copy link
Member Author

mgeier commented Jan 23, 2026

No:

    self.pop("data", None)
    ^^^^^^^^
AttributeError: '_CallbackContext' object has no attribute 'pop'

You could do something like self.data = None, which I used originally. But then I replaced it in #605 to avoid errors of the Pyright static analyzer.

Not sure if there's a need to import contextlib here.

It's not strictly necessary, we could also just use try/except blocks, but they look more clumsy, and importing contextlib costs close to nothing.

It's also not strictly necessary to rely on catching exceptions at all (which is called "it's easier to ask for forgiveness than permission"), but instead check first whether the instance variables are defined or not (which is called "look before you leap").

There are many choices, and it's mostly a matter of taste.

@mgeier mgeier merged commit 8336350 into spatialaudio:master Jan 23, 2026
14 checks passed
@mgeier mgeier deleted the attribute-error branch January 23, 2026 18:28
@mgeier
Copy link
Member Author

mgeier commented Jan 23, 2026

I'm merging this to avoid too many people tripping over this problem, but if you @jared-v-hoyt have (or anybody else has) any ideas for improvements, we can of course do them afterwards. PRs are welcome!

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.

object has no attribute 'out'

2 participants