[PEP 451] "target" arg of find_spec() is not exclusive to reloading.

This commit is contained in:
Eric Snow 2013-11-04 16:40:45 -07:00
parent eb0946e474
commit f96659cba7
1 changed files with 19 additions and 14 deletions

View File

@ -717,22 +717,27 @@ explicit method name aren't worth it.
The "target" parameter of find_spec()
-------------------------------------
A module object with the same name as the "name" argument (or None, the
default) should be passed in to "exising". This argument allows the
finder to build the module spec with more information than is otherwise
available. This is particularly relevant in identifying the loader to
use.
A call to find_spec() may optionally include a "target" argument. This
is the module object that will be used subsequently as the target of
loading. During normal import (and by default) "target" is None,
meaning the target module has yet to be created. During reloading the
module passed in to reload() is passed through to find_spec() as the
target. This argument allows the finder to build the module spec with
more information than is otherwise available. Doing so is particularly
relevant in identifying the loader to use.
Through find_spec() the finder will always identify the loader it
will return in the spec. In the case of reload, at this point the
finder should also decide whether or not the loader supports loading
into the module-to-be-reloaded (which was passed in to find_spec() as
"target"). This decision may entail consulting with the loader. If
the finder determines that the loader does not support reloading that
module, it should either find another loader or raise ImportError
(completely stopping import of the module). This reload decision is
important since, as noted in `How Reloading Will Work`_, loaders will
no longer be able to trivially identify a reload situation on their own.
will return in the spec (or return None). At the point the loader is
identified, the finder should also decide whether or not the loader
supports loading into the target module, in the case that "target" is
passed in. This decision may entail consulting with the loader.
If the finder determines that the loader does not support loading into
the target module, it should either find another loader or raise
ImportError (completely stopping import of the module). This
determination is especially important during reload since, as noted in
`How Reloading Will Work`_, loaders will no longer be able to trivially
identify a reload situation on their own.
Two alternatives were presented to the "target" parameter:
Loader.supports_reload() and adding "target" to Loader.exec_module()