On this page
  1. warnings.warn
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

warnings.warn

Prev: warnings.simplefilter | Up: warnings | Next: warnings.warn_explicit
Rel: warnings.catch_warnings, warnings.deprecated, warnings.filterwarnings, warnings.formatwarning
Ref: docs.python.org — warnings.warn
Tags: #public #python3 #stdlib #warnings


Import

import warnings
from warnings import warn

Signature & Overview

warnings.warn(...)

Issue a warning, or maybe ignore it or raise an exception.

Usage

import warnings

with warnings.catch_warnings(record=True) as caught:
    warnings.simplefilter('always')
    warnings.warn('deprecated param', DeprecationWarning, stacklevel=2)
assert len(caught) == 1

Gotchas

REPL Inspect

from warnings import warn
help(warn)

Linked from

Related notes