[Python-Dev] Tweaking PEP 8 guidelines for use of leading underscores

Steven D'Aprano steve at pearwood.info
Mon Jul 15 05:44:16 CEST 2013


On Mon, Jul 15, 2013 at 10:01:17AM +1000, Cameron Simpson wrote:
> On 15Jul2013 09:48, Steven D'Aprano <steve at pearwood.info> wrote:

> | I'd go further, and say that no more private modules should be 
> | accepted for the std lib unless they have a leading underscore. I 
> | suppose for backwards compatibility reasons, we probably can't go 
> | through the std lib and rename private modules to make it clear they 
> | are private, but we don't have to accept new ones without the 
> | underscore.
> 
> I disagree.
> 
> A private module is a perfectly sane way to implement the internals
> of something, especially if it is subject to implementation change
> in the future.

Of course private modules are sane. I never suggested "no new private 
modules at all". But putting them in the same namespace as public 
modules is not, just to save a leading underscore in the file name.

You don't even have to use the underscore in your own code:

import _stuff as stuff

is allowed, and doesn't make _stuff.py public since imported modules are 
considered implementation details by default.


-- 
Steven


More information about the Python-Dev mailing list