Skip to content

Commit fa8bf7d

Browse files
miss-islingtonAniketsyvstinnerserhiy-storchaka
authored
[3.13] gh-139837: Document attributes of objects recorded by warnings.catch_warnings (GH-139893) (GH-151473) (#151494)
[3.14] gh-139837: Document attributes of objects recorded by warnings.catch_warnings (GH-139893) (GH-151473) * gh-139837: Document attributes of objects recorded by warnings.catch_warnings (GH-139893) (cherry picked from commit 47b7dc7) * Apply suggestions from code review --------- (cherry picked from commit eb612f4) Co-authored-by: Aniket <148300120+Aniketsy@users.noreply.github.com> Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 6971e05 commit fa8bf7d

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

Doc/library/warnings.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,23 @@ Available Context Managers
604604
If the *record* argument is :const:`False` (the default) the context manager
605605
returns :class:`None` on entry. If *record* is :const:`True`, a list is
606606
returned that is progressively populated with objects as seen by a custom
607-
:func:`showwarning` function (which also suppresses output to ``sys.stdout``).
608-
Each object in the list has attributes with the same names as the arguments to
609-
:func:`showwarning`.
607+
:func:`showwarning` function (which also suppresses output to ``sys.stderr``).
608+
Each object in the list is guaranteed to have the following attributes:
609+
610+
- ``message``: the warning message (an instance of :exc:`Warning`)
611+
- ``category``: the warning category (a subclass of :exc:`Warning`)
612+
- ``filename``: the file name where the warning occurred (:class:`str`)
613+
- ``lineno``: the line number in the file (:class:`int`)
614+
- ``file``: the file object used for output (if any), or ``None``
615+
- ``line``: the line of source code (if available), or ``None``
616+
- ``source``: the original object that generated the warning (if
617+
available), or ``None``
618+
619+
.. versionchanged:: 3.6
620+
The ``source`` attribute was added.
621+
622+
The type of these objects is not specified and may change; only the
623+
presence of these attributes is guaranteed.
610624

611625
The *module* argument takes a module that will be used instead of the
612626
module returned when you import :mod:`warnings` whose filter will be

0 commit comments

Comments
 (0)