[PEP 451] "target" arg of find_spec() is not exclusive to reloading.
This commit is contained in:
parent
eb0946e474
commit
f96659cba7
33
pep-0451.txt
33
pep-0451.txt
|
@ -717,22 +717,27 @@ explicit method name aren't worth it.
|
||||||
The "target" parameter of find_spec()
|
The "target" parameter of find_spec()
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
|
||||||
A module object with the same name as the "name" argument (or None, the
|
A call to find_spec() may optionally include a "target" argument. This
|
||||||
default) should be passed in to "exising". This argument allows the
|
is the module object that will be used subsequently as the target of
|
||||||
finder to build the module spec with more information than is otherwise
|
loading. During normal import (and by default) "target" is None,
|
||||||
available. This is particularly relevant in identifying the loader to
|
meaning the target module has yet to be created. During reloading the
|
||||||
use.
|
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
|
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
|
will return in the spec (or return None). At the point the loader is
|
||||||
finder should also decide whether or not the loader supports loading
|
identified, the finder should also decide whether or not the loader
|
||||||
into the module-to-be-reloaded (which was passed in to find_spec() as
|
supports loading into the target module, in the case that "target" is
|
||||||
"target"). This decision may entail consulting with the loader. If
|
passed in. This decision may entail consulting with the loader.
|
||||||
the finder determines that the loader does not support reloading that
|
|
||||||
module, it should either find another loader or raise ImportError
|
If the finder determines that the loader does not support loading into
|
||||||
(completely stopping import of the module). This reload decision is
|
the target module, it should either find another loader or raise
|
||||||
important since, as noted in `How Reloading Will Work`_, loaders will
|
ImportError (completely stopping import of the module). This
|
||||||
no longer be able to trivially identify a reload situation on their own.
|
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:
|
Two alternatives were presented to the "target" parameter:
|
||||||
Loader.supports_reload() and adding "target" to Loader.exec_module()
|
Loader.supports_reload() and adding "target" to Loader.exec_module()
|
||||||
|
|
Loading…
Reference in New Issue