mirror of
https://github.com/python/cpython.git
synced 2025-11-28 14:11:15 +00:00
Issue #15482: Properly document the default 'level' parameter for
__import__(). To help explain why the -1 default value is typically not seen, a note about how import statements only use values of >= 0 is also noted.
This commit is contained in:
parent
03e2180b3f
commit
9b000e7a68
2 changed files with 11 additions and 5 deletions
|
|
@ -1410,7 +1410,7 @@ are always available. They are listed here in alphabetical order.
|
||||||
True
|
True
|
||||||
|
|
||||||
|
|
||||||
.. function:: __import__(name, globals={}, locals={}, fromlist=[], level=0)
|
.. function:: __import__(name, globals={}, locals={}, fromlist=[], level=-1)
|
||||||
|
|
||||||
.. index::
|
.. index::
|
||||||
statement: import
|
statement: import
|
||||||
|
|
@ -1435,10 +1435,13 @@ are always available. They are listed here in alphabetical order.
|
||||||
not use its *locals* argument at all, and uses its *globals* only to
|
not use its *locals* argument at all, and uses its *globals* only to
|
||||||
determine the package context of the :keyword:`import` statement.
|
determine the package context of the :keyword:`import` statement.
|
||||||
|
|
||||||
*level* specifies whether to use absolute or relative imports. ``0`` (the
|
*level* specifies whether to use absolute or relative imports. ``0``
|
||||||
default) means only perform absolute imports. Positive values for
|
means only perform absolute imports. Positive values for *level* indicate the
|
||||||
*level* indicate the number of parent directories to search relative to the
|
number of parent directories to search relative to the directory of the
|
||||||
directory of the module calling :func:`__import__`.
|
module calling :func:`__import__`. Negative values attempt both an implicit
|
||||||
|
relative import and an absolute import (usage of negative values for *level*
|
||||||
|
are strongly discouraged as future versions of Python do not support such
|
||||||
|
values). Import statements only use values of 0 or greater.
|
||||||
|
|
||||||
When the *name* variable is of the form ``package.module``, normally, the
|
When the *name* variable is of the form ``package.module``, normally, the
|
||||||
top-level package (the name up till the first dot) is returned, *not* the
|
top-level package (the name up till the first dot) is returned, *not* the
|
||||||
|
|
|
||||||
|
|
@ -465,6 +465,9 @@ Build
|
||||||
Documentation
|
Documentation
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
- Issue 15482: Properly document the default 'level' value for __import__()
|
||||||
|
while warning about using negative values.
|
||||||
|
|
||||||
- Issue #15230: Clearly document some of the limitations of the runpy
|
- Issue #15230: Clearly document some of the limitations of the runpy
|
||||||
module and nudge readers towards importlib when appropriate.
|
module and nudge readers towards importlib when appropriate.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue