> __all__ = (Class.__name__, func.__name__, ...)
>
> So I have to put it at the end of the module. I do this because if I
> change the class or function name and I forget to change it in
> __all__, I get an exception.

I certainly will not claim to be the arbitrator of good and bad practices but that seems reasonable enough.

It is worth pointing out that it's pretty easy to unit test `__all__`

```
# module/__init__.py
__all__ = 'Foo', 'Bar'

class Foo: pass
```

```
# tests/test_imports.py
def test_star():
      # will raise `AttributeError: module 'module' has not attribute 'Bar'`
      from module import *
```     

> from .a import *
> from .b import *

> __all__ = a.__all__ + b.__all__

Assuming you mean:
```
from . import a
from . import b
from .a import *
from .b import *
__all__ = a.__all__ + b.__all__  
```
It is fairly unnecessary if you aren't adding more names. but definitely isn't harmful.


On Fri, Mar 5, 2021 at 12:11 PM Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
On Wed, 3 Mar 2021 at 23:59, Brendan Barnwell <brenbarn@brenbarn.net> wrote:
>  But usually you want to define it at the beginning as a sort of
> documentation aid ("this is the public API").

This is a little off-topic, but I'm curious, since usually, for public
functions and classes, I do

__all__ = (Class.__name__, func.__name__, ...)

So I have to put it at the end of the module. I do this because if I
change the class or function name and I forget to change it in
__all__, I get an exception.

Furthermore, if there's a module composed by submodules, I usually do

from .a import *
from .b import *

__all__ = a.__all__ + b.__all__

In your opinion, these are good or bad practices?
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/AZLCRXYWZUS63RDSAUEQ52SGRXGKY3KE/
Code of Conduct: http://python.org/psf/codeofconduct/