[typing] why is import aliasing preferred to __all__ to explicitly export module variables?

Why is import aliasing preferred to __all__ to explicitly export module variables? What is the reason for this preference? Is this documented anywhere?

nn.Parameter, nn.DataParallel
torch.testing.assert_close

Based on this linked issue it seems pyright complained about this import and claimed nn.Parameter wasn’t exported.
This post describes the issue in more detail.
pyright also describes its expectations here.

1 Like

Thanks @ptrblck, from what you linked I suppose this is a reason:

The __all__ variable designates “symbols that should be imported by a wildcard import”, so it often overlaps with the notion of “symbols that are meant to be publicly visible from a module”, but there are cases where the former is a subset of the latter.

I still wonder if there is an official PyTorch position on this… like if there is some documented reason we are not wanting to expose these variables thru import *.

The corresponding PyTorch issue is here describing the other linked issues raised by pyright. If I interpret @albanD 's response correctly there were no arguments against fixing the pyright complains.

Another data point is the public API definition that we have: Public API definition and documentation · pytorch/pytorch Wiki · GitHub

But for these, yes we’re happy to fix them!

1 Like