Kaydet (Commit) 2bfe3a9d authored tarafından Nick Coghlan's avatar Nick Coghlan

Cover ImportWarning, PendingDeprecationWarning and simplefilter() in the warnings module docs

üst b6983bbe
...@@ -71,6 +71,11 @@ runtime features.} ...@@ -71,6 +71,11 @@ runtime features.}
\lineii{FutureWarning}{Base category for warnings about constructs \lineii{FutureWarning}{Base category for warnings about constructs
that will change semantically in the future.} that will change semantically in the future.}
\lineii{PendingDeprecationWarning}{Base category for warnings about
features that will be deprecated in the future (ignored by default).}
\lineii{ImportWarning}{Base category for warnings triggered during the
process of importing a module (ignored by default).}
\end{tableii} \end{tableii}
While these are technically built-in exceptions, they are documented While these are technically built-in exceptions, they are documented
...@@ -143,6 +148,17 @@ arguments for all \programopt{-W} options without interpretation in ...@@ -143,6 +148,17 @@ arguments for all \programopt{-W} options without interpretation in
it is first imported (invalid options are ignored, after printing a it is first imported (invalid options are ignored, after printing a
message to \code{sys.stderr}). message to \code{sys.stderr}).
The warnings that are ignored by default may be enabled by passing
\programopt{-Wd} to the interpreter. This enables default handling
for all warnings, including those that are normally ignored by
default. This is particular useful for enabling ImportWarning when
debugging problems importing a developed package. ImportWarning can
also be enabled explicitly in Python code using:
\begin{verbatim}
warnings.simplefilter('default', ImportWarning)
\end{verbatim}
\subsection{Available Functions \label{warning-functions}} \subsection{Available Functions \label{warning-functions}}
...@@ -209,14 +225,26 @@ Insert an entry into the list of warnings filters. The entry is ...@@ -209,14 +225,26 @@ Insert an entry into the list of warnings filters. The entry is
inserted at the front by default; if \var{append} is true, it is inserted at the front by default; if \var{append} is true, it is
inserted at the end. inserted at the end.
This checks the types of the arguments, compiles the message and This checks the types of the arguments, compiles the message and
module regular expressions, and inserts them as a tuple in front module regular expressions, and inserts them as a tuple in the
of the warnings filter. Entries inserted later override entries list of warnings filters. Entries closer to the front of the list
inserted earlier, if both match a particular warning. Omitted override entries later in the list, if both match a particular
arguments default to a value that matches everything. warning. Omitted arguments default to a value that matches
everything.
\end{funcdesc}
\begin{funcdesc}{simplefilter}{action\optional{,
category\optional{,
lineno\optional{, append}}}}
Insert a simple entry into the list of warnings filters. The meaning
of the function parameters is as for \function{filterwarnings()}, but
regular expressions are not needed as the filter inserted always
matches any message in any module as long as the category and line
number match.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{resetwarnings}{} \begin{funcdesc}{resetwarnings}{}
Reset the warnings filter. This discards the effect of all previous Reset the warnings filter. This discards the effect of all previous
calls to \function{filterwarnings()}, including that of the calls to \function{filterwarnings()}, including that of the
\programopt{-W} command line options. \programopt{-W} command line options and calls to
\function{simplefilter()}.
\end{funcdesc} \end{funcdesc}
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