On 15 July 2013 02:15, Gregory P. Smith <g...@krypto.org> wrote:
> On Sun, Jul 14, 2013 at 4:09 AM, Nick Coghlan <ncogh...@gmail.com> wrote:
>> as Python users may rely on introspection to identify available
>> functionality and may be misled into believing an API without a leading
>> underscore is in fact a public API with the standard backwards compatibility
>> guarantees.
>
>
> While true, I'm not sure the last part of the sentence is necessary. Once
> we've established that a leading _ indicates something is private there
> isn't much point in explaining the various ways people might find them.  I'm
> happy regardless of this bit being there.

You'd be surprised how many  non-core devs react with astonishment
when I suggest that not documenting something isn't enough to avoid
having users consider it a supported public API - they usually get it
after I point out how far you can usually get just by using dir() and
help() to play with a new library at the interactive prompt instead of
looking at out-of-band docs. I figure including the second part will
help prevent some "But why?" reactions in the future.

I think Steven has a reasonable point about being clearer that an
explicit leading underscore is the preferred solution for any new
private modules, though, so here's an updated proposal:

=================
Private interfaces

Unless explicitly documented otherwise, a leading underscore on any
name indicates that it is an internal implementation detail and any
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 Python
users may rely on introspection to identify available functionality
and may be misled into believing an API without a leading underscore
is in fact a public API with the standard backwards compatibility
guarantees.

While the explicit use of a leading underscore in the names of private
modules is preferred, all test modules and all modules that are not
explicitly covered in the documentation are also considered private
interfaces, even when their names do not start with a leading
underscore and even if they include a module level documentation
string. This includes submodules of packages that are documented as if
they were a single module.

Similarly, the specific modules and external APIs imported by a module
are always considered an implementation detail. Other modules should
not rely on indirect access to such imported interfaces unless they
are an explicitly documented part of the containing module's API (such
as ``os.path`` or a package ``__init__`` module that exposes
functionality from submodules).
=================



--
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to