Background
Reading the answers for this question, and looking at the Pandas and Django repository.
If __all__
is defined then when you import *
from your package, only the names defined in __all__
are imported in the current namespace.
I immediately draw the conclusion that if I use import package.specific_module
, then there is no benefit of defining __all__
.
However, digging around some common project like Pandas, Django... I realised that developers import specific modules and pass all of them as a list to the __all__
variable, like the below example:
from pandas.core.groupby.generic import (
DataFrameGroupBy,
NamedAgg,
SeriesGroupBy,
)
from pandas.core.groupby.groupby import GroupBy
from pandas.core.groupby.grouper import Grouper
__all__ = [
"DataFrameGroupBy",
"NamedAgg",
"SeriesGroupBy",
"GroupBy",
"Grouper",
]
Question
I know that pydocs
will ignore modules that aren't in the __all__
variable.
But besides that, what are the other benefits of importing specific modules from within __init__.py
and at the same time pass them as a list to the __all__
variable? isn't it redundant?