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. The expression is compiled to always be
160 * *category* is a class (a subclass of :exc:`Warning`) of which the warning
166 * *lineno* is an integer that the line number where the warning occurred must
169 Since the :exc:`Warning` class is derived from the built-in :exc:`Exception`
170 class, to turn a warning into an error we simply raise ``category(message)``.
172 If a warning is reported and doesn't match any registered filter then the
176 .. _describing-warning-filters:
178 Describing Warning Filters
193 The meaning of each of these fields is as described in :ref:`warning-filter`.
200 Commonly used warning filters apply to either all warnings, warnings in a
214 .. _default-warning-filter:
216 Default Warning Filter
219 By default, Python installs several warning filters, which can be overridden by
223 In regular release builds, the default warning filter has the following entries
232 In a :ref:`debug build <debug-build>`, the list of default warning filters is empty.
291 If you are using code that you know will raise a warning, such as a deprecated
292 function, but do not want to see the warning (even when warnings have been
294 the warning using the :class:`catch_warnings` context manager::
306 allows you to use known-deprecated code without having to see the warning while
307 not suppressing the warning for other code that might not be aware of its use
332 # Trigger a warning.
340 ``always``. One thing to be aware of is that if a warning has already been
342 set the warning will not be seen again unless the warnings registry related to
343 the warning has been cleared.
353 When testing multiple operations that raise the same kind of warning, it
355 a new warning (e.g. set warnings to be raised as exceptions and check the
356 operations raise exceptions, check that the length of the warning list
366 Warning categories that are primarily of interest to Python developers (rather
397 Issue a warning, or maybe ignore it or raise an exception. The *category*
398 argument, if given, must be a :ref:`warning category class <warning-categories>`; it
399 defaults to :exc:`UserWarning`. Alternatively, *message* can be a :exc:`Warning` instance,
402 exception if the particular warning issued is changed into an error by the
403 :ref:`warnings filter <warning-filter>`. The *stacklevel* argument can be used by wrapper
409 This makes the warning refer to :func:`deprecation`'s caller, rather than to the
411 of the warning message).
426 ``.py`` stripped; if no registry is passed, the warning is never suppressed.
427 *message* must be a string and *category* a subclass of :exc:`Warning` or
428 *message* may be a :exc:`Warning` instance, in which case *category* will be
432 for which the warning is issued. (This argument is used to support displaying
445 Write a warning to a file. The default implementation calls
449 *line* is a line of source code to be included in the warning
456 Format a warning the standard way. This returns a string which may contain
458 be included in the warning message; if *line* is not supplied,
463 .. function:: filterwarnings(action, message='', category=Warning, module='', lineno=0, append=Fals…
466 <warning-filter>`. The entry is inserted at the front by default; if
471 particular warning. Omitted arguments default to a value that matches
475 .. function:: simplefilter(action, category=Warning, lineno=0, append=False)
478 <warning-filter>`. The meaning of the function parameters is as for