Commit 077ffbb2 authored by Barry Warsaw's avatar Barry Warsaw

Finally, a coherent set of terminology for all the lil' beasties involved.

parent c215e7e7
...@@ -315,6 +315,13 @@ Glossary ...@@ -315,6 +315,13 @@ Glossary
role in places where a constant hash value is needed, for example as a key role in places where a constant hash value is needed, for example as a key
in a dictionary. in a dictionary.
import path
A list of locations (or :term:`path entries <path entry>`) that are
searched by the :term:`path importer` for modules to import. During
import, this list of locations usually comes from :data:`sys.path`, but
for subpackages it may also come from the parent package's ``__path__``
attribute.
importing importing
The process by which Python code in one module is made available to The process by which Python code in one module is made available to
Python code in another module. Python code in another module.
...@@ -446,8 +453,8 @@ Glossary ...@@ -446,8 +453,8 @@ Glossary
meta path finder meta path finder
A finder returned by a search of :data:`sys.meta_path`. Meta path A finder returned by a search of :data:`sys.meta_path`. Meta path
finders are related to, but different from :term:`sys path finders <sys finders are related to, but different from :term:`path entry finders
path finder>`. <path entry finder>`.
metaclass metaclass
The class of a class. Class definitions create a class name, a class The class of a class. Class definitions create a class name, a class
...@@ -541,9 +548,23 @@ Glossary ...@@ -541,9 +548,23 @@ Glossary
subpackages. Technically, a package is a Python module with an subpackages. Technically, a package is a Python module with an
``__path__`` attribute. ``__path__`` attribute.
path entry
A single location on the :term:`import path` which the :term:`path
importer` consults to find modules for importing.
path entry finder
A :term:`finder` returned by a callable on :data:`sys.path_hooks`
(i.e. a :term:`path entry hook`) which knows how to locate modules given
a :term:`path entry`.
path entry hook
A callable on the :data:`sys.path_hook` list which returns a :term:`path
entry finder` if it knows how to find modules on a specific :term:`path
entry`.
path importer path importer
A built-in :term:`finder` / :term:`loader` that knows how to find and One of the default :term:`meta path finders <meta path finder>` which
load modules from the file system. searches an :term:`import path` for modules.
portion portion
A set of files in a single directory (possibly stored in a zip file) A set of files in a single directory (possibly stored in a zip file)
...@@ -671,11 +692,6 @@ Glossary ...@@ -671,11 +692,6 @@ Glossary
:meth:`~collections.somenamedtuple._asdict`. Examples of struct sequences :meth:`~collections.somenamedtuple._asdict`. Examples of struct sequences
include :data:`sys.float_info` and the return value of :func:`os.stat`. include :data:`sys.float_info` and the return value of :func:`os.stat`.
sys path finder
A finder returned by a search of :data:`sys.path` by the :term:`path
importer`. Sys path finders are related to, but different from
:term:`meta path finders <meta path finder>`.
triple-quoted string triple-quoted string
A string which is bound by three instances of either a quotation mark A string which is bound by three instances of either a quotation mark
(") or an apostrophe ('). While they don't provide any functionality (") or an apostrophe ('). While they don't provide any functionality
......
...@@ -652,15 +652,16 @@ Modules ...@@ -652,15 +652,16 @@ Modules
object: module object: module
Modules are a basic organizational unit of Python code, and are created by Modules are a basic organizational unit of Python code, and are created by
the :ref:`importmachinery` as invoked either by the :keyword:`import` the :ref:`import system <importsystem>` as invoked either by the
statement (see section :ref:`import`) or by calling the built in :keyword:`import` statement (see :keyword:`import`), or by calling
:func:`__import__` function. A module object has a namespace implemented functions such as :func:`importlib.import_module` and built-in
by a dictionary object (this is the dictionary referenced by the :func:`__import__`. A module object has a namespace implemented by a
``__globals__`` attribute of functions defined in the module). Attribute dictionary object (this is the dictionary referenced by the ``__globals__``
references are translated to lookups in this dictionary, e.g., ``m.x`` is attribute of functions defined in the module). Attribute references are
equivalent to ``m.__dict__["x"]``. A module object does not contain the translated to lookups in this dictionary, e.g., ``m.x`` is equivalent to
code object used to initialize the module (since it isn't needed once the ``m.__dict__["x"]``. A module object does not contain the code object used
initialization is done). to initialize the module (since it isn't needed once the initialization is
done).
Attribute assignment updates the module's namespace dictionary, e.g., Attribute assignment updates the module's namespace dictionary, e.g.,
``m.x = 1`` is equivalent to ``m.__dict__["x"] = 1``. ``m.x = 1`` is equivalent to ``m.__dict__["x"] = 1``.
......
...@@ -24,7 +24,7 @@ interfaces available to C/C++ programmers in detail. ...@@ -24,7 +24,7 @@ interfaces available to C/C++ programmers in detail.
lexical_analysis.rst lexical_analysis.rst
datamodel.rst datamodel.rst
executionmodel.rst executionmodel.rst
import_machinery.rst import.rst
expressions.rst expressions.rst
simple_stmts.rst simple_stmts.rst
compound_stmts.rst compound_stmts.rst
......
...@@ -662,14 +662,17 @@ The :keyword:`import` statement ...@@ -662,14 +662,17 @@ The :keyword:`import` statement
Import statements are executed in two steps: (1) find a module, loading and Import statements are executed in two steps: (1) find a module, loading and
initializing it if necessary; (2) define a name or names in the local initializing it if necessary; (2) define a name or names in the local
namespace (of the scope where the :keyword:`import` statement occurs). The namespace (of the scope where the :keyword:`import` statement occurs).
statement comes in two forms differing on whether it uses the :keyword:`from` Step (1) may be performed recursively if the named module is a submodule or
keyword. The first form (without :keyword:`from`) repeats these steps for each subpackage of a parent package.
identifier in the list. The form with :keyword:`from` performs step (1) once,
and then performs step (2) repeatedly. The :keyword:`import` statement comes in two forms differing on whether it
uses the :keyword:`from` keyword. The first form (without :keyword:`from`)
repeats these steps for each identifier in the list. The form with
:keyword:`from` performs step (1), and then performs step (2) repeatedly.
The details of step (1), finding and loading modules is described in greater The details of step (1), finding and loading modules is described in greater
detail in the section on the :ref:`import machinery <importmachinery>`, which detail in the section on the :ref:`import system <importsystem>`, which
also describes the various types of packages and modules that can be imported, also describes the various types of packages and modules that can be imported,
as well as all the hooks that can be used to customize Python's import. as well as all the hooks that can be used to customize Python's import.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment