Lines Matching full:warning
1 :mod:`warnings` --- Warning control
5 :synopsis: Issue warning messages and control their disposition.
13 Warning messages are typically issued in situations where it is useful to alert
16 might want to issue a warning when a program uses an obsolete module.
22 Warning messages are normally written to :data:`sys.stderr`, but their disposition
24 exceptions. The disposition of warnings can vary based on the :ref:`warning category
25 <warning-categories>`, the text of the warning message, and the source location where it
26 is issued. Repetitions of a particular warning for the same source location are
29 There are two stages in warning control: first, each time a warning is issued, a
33 The determination whether to issue a warning message is controlled by the
34 :ref:`warning filter <warning-filter>`, which is a sequence of matching rules and actions. Rules ca…
38 The printing of warning messages is done by calling :func:`showwarning`, which
50 Warning Categories
53 There are a number of built-in exceptions that represent warning categories.
57 :ref:`built-in exceptions <warning-categories-as-exceptions>`, they are
60 User code can define additional warning categories by subclassing one of the
61 standard warning categories. A warning category must always be a subclass of
62 the :exc:`Warning` class.
71 | :exc:`Warning` | This is the base class of all warning |
128 specifications; any specific warning is matched against each filter
140 | | line number) where the warning is issued |
149 | | warnings for each module where the warning |
157 the warning message must match, case-insensitively. In :option:`-W` and
159 warning message must contain (case-insensitively), ignoring any whitespace at
162 * *category* is a class (a subclass of :exc:`Warning`) of which the warning
171 * *lineno* is an integer that the line number where the warning occurred must
174 Since the :exc:`Warning` class is derived from the built-in :exc:`Exception`
175 class, to turn a warning into an error we simply raise ``category(message)``.
177 If a warning is reported and doesn't match any registered filter then the
181 .. _describing-warning-filters:
183 Describing Warning Filters
198 The meaning of each of these fields is as described in :ref:`warning-filter`.
205 Commonly used warning filters apply to either all warnings, warnings in a
218 .. _default-warning-filter:
220 Default Warning Filter
223 By default, Python installs several warning filters, which can be overridden by
227 In regular release builds, the default warning filter has the following entries
236 In a :ref:`debug build <debug-build>`, the list of default warning filters is empty.
295 If you are using code that you know will raise a warning, such as a deprecated
296 function, but do not want to see the warning (even when warnings have been
298 the warning using the :class:`catch_warnings` context manager::
310 allows you to use known-deprecated code without having to see the warning while
311 not suppressing the warning for other code that might not be aware of its use
336 # Trigger a warning.
344 ``always``. One thing to be aware of is that if a warning has already been
346 set the warning will not be seen again unless the warnings registry related to
347 the warning has been cleared.
357 When testing multiple operations that raise the same kind of warning, it
359 a new warning (e.g. set warnings to be raised as exceptions and check the
360 operations raise exceptions, check that the length of the warning list
370 Warning categories that are primarily of interest to Python developers (rather
401 Issue a warning, or maybe ignore it or raise an exception. The *category*
402 argument, if given, must be a :ref:`warning category class <warning-categories>`; it
403 defaults to :exc:`UserWarning`. Alternatively, *message* can be a :exc:`Warning` instance,
406 exception if the particular warning issued is changed into an error by the
407 :ref:`warnings filter <warning-filter>`. The *stacklevel* argument can be used by wrapper
413 This makes the warning refer to :func:`deprecation`'s caller, rather than to the
415 of the warning message).
430 ``.py`` stripped; if no registry is passed, the warning is never suppressed.
431 *message* must be a string and *category* a subclass of :exc:`Warning` or
432 *message* may be a :exc:`Warning` instance, in which case *category* will be
436 for which the warning is issued. (This argument is used to support displaying
449 Write a warning to a file. The default implementation calls
453 *line* is a line of source code to be included in the warning
460 Format a warning the standard way. This returns a string which may contain
462 be included in the warning message; if *line* is not supplied,
467 .. function:: filterwarnings(action, message='', category=Warning, module='', lineno=0, append=Fals…
470 <warning-filter>`. The entry is inserted at the front by default; if
475 particular warning. Omitted arguments default to a value that matches
479 .. function:: simplefilter(action, category=Warning, lineno=0, append=False)
482 <warning-filter>`. The meaning of the function parameters is as for
498 .. class:: catch_warnings(*, record=False, module=None, action=None, category=Warning, lineno=0, ap…