20.07.19 09:03, Kyle Stanley пише:
Rather than it being on a case-by-case basis, would it be reasonable to 
establish a universal standard across stdlib for defining modules as public to 
apply to older modules as well? I think that it would prove to be quite 
beneficial to create an explicit definition of what is considered public. If we 
don't, there is likely to be further confusion on this topic, particularly from 
users.

There would be some overhead cost associated with ensuring that every 
non-public function is is proceeded by an underscore, but adding public 
functions to __all__ could safely be automated with something like this 
(https://bugs.python.org/issue29446#msg287049):

__all__ = [name for name, obj in globals().items() if not name.startswith('_') 
and not isinstance(obj, types.ModuleType)]

or a bit more lazily:

__all__ = [name for name in globals() if not name.startswith('_')]

Personally, I think the benefit of avoiding confusion on this issue and 
providing consistency to users would far outweigh the cost of implementing it.

__all__ is not needed if we can make all public names non-undescored and all non-public names underscored. The problem in issue29446 is that we can't do this in case of tkinter. We can't add an underscore to "wantobjects", because this name is the part of the public interface, but we also do not want to make it imported by the star import. So we need __all__ which includes all "normal" public names except "wantobjects".
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/UNPJYSIUTQPPM6CKCDX5AEKB7CPSLNHK/

Reply via email to