On 3/5/21 12:41 PM, Caleb Donovick wrote:

 > __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__
```

Actually, Marko's version works, and is the same style used by asyncio.  
Apparently,

  from .a import *

also adds `a` to the module's namespace.

--
~Ethan~
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@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/XIWHAUXPEO6U2ZYNUFGHQDQEROUDVWRK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to