diff options
author | Walter Dörwald <walter@livinglogic.de> | 2002-03-21 10:38:40 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2002-03-21 10:38:40 (GMT) |
commit | b25c2b0a4a46156bd8efa9eab39503e18fa0b805 (patch) | |
tree | 8a48a9537b24e37ab60c2f69404a848451251234 /Doc | |
parent | 047c05ebc4ce00f9ca8ccc5b8df437d758d130e8 (diff) | |
download | cpython-b25c2b0a4a46156bd8efa9eab39503e18fa0b805.zip cpython-b25c2b0a4a46156bd8efa9eab39503e18fa0b805.tar.gz cpython-b25c2b0a4a46156bd8efa9eab39503e18fa0b805.tar.bz2 |
[Apply SF patch #504943]
This patch makes it possible to pass Warning instances as the first
argument to warnings.warn. In this case the category argument
will be ignored. The message text used will be str(warninginstance).
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/lib/libwarnings.tex | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Doc/lib/libwarnings.tex b/Doc/lib/libwarnings.tex index b7c7d63..573d99c 100644 --- a/Doc/lib/libwarnings.tex +++ b/Doc/lib/libwarnings.tex @@ -145,7 +145,10 @@ message to \code{sys.stderr}). \begin{funcdesc}{warn}{message\optional{, category\optional{, stacklevel}}} Issue a warning, or maybe ignore it or raise an exception. The \var{category} argument, if given, must be a warning category class -(see above); it defaults to \exception{UserWarning}. This function +(see above); it defaults to \exception{UserWarning}. Alternatively +\var{message} can be a \exception{Warning} instance, in which case +\var{category} will be ignore and \code{message.__class__} will be used. +In this case the message text will be \code{str(message)}. This function raises an exception if the particular warning issued is changed into an error by the warnings filter see above. The \var{stacklevel} argument can be used by wrapper functions written in Python, like @@ -169,6 +172,9 @@ filename and line number, and optionally the module name and the registry (which should be the \code{__warningregistry__} dictionary of the module). The module name defaults to the filename with \code{.py} stripped; if no registry is passed, the warning is never suppressed. +\var{message} must be a string and \var{category} a subclass of +\exception{Warning} or \var{message} may be a \exception{Warning} instance, +in which case \var{category} will be ignored. \end{funcdesc} \begin{funcdesc}{showwarning}{message, category, filename, |