Redirecting stdout to avoid banners while `import`ing

The reason why is that this code is not run when the module is loaded from a precompiled file. The way precompilation of packages work is to deserialize the state of the module to a file during precompilation and when loading, the state is simply deserialized and then the __init__ function of the module is run. No top-level code is run when the module is loaded.

I’m not really sure how to “hook” into the __init__ function of dependent packages though.

Unconditional printing of banners and such on package load is really user-hostile behavior…

2 Likes