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

Nick Coghlan ncoghlan at gmail.com
Sun Jul 14 10:11:18 CEST 2013

Currently, the naming section of PEP 8 doesn't say very much about what a
leading underscore *means* in the Python standard library.

I would like to add a new "Private interfaces" subsection under "Naming
Conventions" to say the following:

Private interfaces

Unless explicitly documented otherwise, a leading underscore on any name
indicates that it is an internal implementation detail and backwards
compatibility guarantees do not apply. It is strongly encouraged that
private APIs (whether modules, classes, functions, attributes or other
names) be clearly marked in this way, as many Python users rely on
introspection to identify available functionality and may be mislead into
believing an API without the leading underscore is in fact a public API
with the standard backwards compatibility guarantees.

All test modules are also considered private interfaces.

Even though they typically lack the leading underscore, modules imported by
another module are also considered an implementation detail. Other modules
*should* not rely on indirect access to such modules unless they are an
explicitly documented part of the API (such as ``os.path``).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130714/3464a429/attachment.html>

More information about the Python-Dev mailing list