__all__ attribute: bug and proposal

Chris Angelico rosuav at gmail.com
Mon Jun 27 17:32:42 EDT 2016


On Tue, Jun 28, 2016 at 6:56 AM, Pavel S <pavel at schon.cz> wrote:
> Porposal: allow putting objects into __all__ directly, so possible problems will be found earlier:
>
> # module foo.py
> class A: pass
> class B: pass
> class C: pass
>
> __all__ = (A, B, C)
>
> Note: this currently don't work.
>
>>>> from foo import *
> TypeError: attribute name must be string, not 'type'

How would it know what names to import them under? It's all very well
with classes and functions (you could mandate that it uses the
canonical name), but what about integers or strings?

ChrisA



More information about the Python-list mailing list