mirror of
https://github.com/python/cpython.git
synced 2025-11-08 13:42:22 +00:00
Expand on the semantics of reload(). Closes #919099.
This commit is contained in:
parent
0690512a7d
commit
8e6ad6fbe9
1 changed files with 24 additions and 2 deletions
|
|
@ -785,14 +785,36 @@ class C(object):
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
\begin{funcdesc}{reload}{module}
|
\begin{funcdesc}{reload}{module}
|
||||||
Re-parse and re-initialize an already imported \var{module}. The
|
Reload a previously imported \var{module}. The
|
||||||
argument must be a module object, so it must have been successfully
|
argument must be a module object, so it must have been successfully
|
||||||
imported before. This is useful if you have edited the module
|
imported before. This is useful if you have edited the module
|
||||||
source file using an external editor and want to try out the new
|
source file using an external editor and want to try out the new
|
||||||
version without leaving the Python interpreter. The return value is
|
version without leaving the Python interpreter. The return value is
|
||||||
the module object (the same as the \var{module} argument).
|
the module object (the same as the \var{module} argument).
|
||||||
|
|
||||||
There are a number of caveats:
|
When \code{reload(module)} is executed:
|
||||||
|
|
||||||
|
\begin{itemize}
|
||||||
|
|
||||||
|
\item{Python modules' code is recompiled and the module-level code
|
||||||
|
reexecuted, defining a new set of objects which are bound to names in
|
||||||
|
the module's dictionary. The \code{init} function of extension
|
||||||
|
modules is not called a second time.}
|
||||||
|
|
||||||
|
\item{As with all other objects in Python the old objects are only
|
||||||
|
reclaimed after their reference counts drop to zero.}
|
||||||
|
|
||||||
|
\item{The names in the module namespace are updated to point to
|
||||||
|
any new or changed objects.}
|
||||||
|
|
||||||
|
\item{Other references to the old objects (such as names external
|
||||||
|
to the module) are not rebound to refer to the new objects and
|
||||||
|
must be updated in each namespace where they occur if that is
|
||||||
|
desired.}
|
||||||
|
|
||||||
|
\end{itemize}
|
||||||
|
|
||||||
|
There are a number of other caveats:
|
||||||
|
|
||||||
If a module is syntactically correct but its initialization fails,
|
If a module is syntactically correct but its initialization fails,
|
||||||
the first \keyword{import} statement for it does not bind its name
|
the first \keyword{import} statement for it does not bind its name
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue