PEP 842: Module Exports

Good questions. Adding to __all__ is overwhelmingly preferred to sprinkling your imports with noqa. My guess is that it’s because it declares intent (“it’s in the public interface”). noqa is typically a last resort.

Even a hub module is not supposed to have unused imports. Hub modules contain both “exports”:

from .x.y import z
# ...
__all__ = ["z", ...]

And sometimes even imports, for example warnings to warn on imports that will change.

Those imports should not be unused, but they don’t belong in __all__ either.

Yeah, it’s pretty rare, but it happens: from multiprocessing.spawn import _main