Skip to content

Commit 7e814f5

Browse files
author
Devesh
committed
gh-54643: Doument the rules for public names in the tutorial
1 parent 7c653e2 commit 7e814f5

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Doc/tutorial/modules.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,3 +603,17 @@ modules found in a package.
603603
.. [#] In fact function definitions are also 'statements' that are 'executed'; the
604604
execution of a module-level function definition adds the function name to
605605
the module's global namespace.
606+
607+
Public Names
608+
------------
609+
610+
.. note::
611+
When using a module, it is important to know which names (functions, classes, variables) are intended for you to use (the *public API*), and which are internal details that might change.
612+
613+
The rules for public names are:
614+
615+
1. If a module defines an ``__all__`` variable, only the names listed inside it are considered public. All remaining names are considered private.
616+
617+
2. If a module does not define an ``__all__`` variable, then any name that does NOT start with an underscore (``_``) is considered public.
618+
619+
3. Any imported names from other modules are not public, unless they are explicitly included in ``__all__``.

0 commit comments

Comments
 (0)