From 70b71497fb2b139f19795467e8546bab4fbe65c1 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 5 Oct 2026 14:58:33 +0200 Subject: [PATCH 1/2] [logging] Normalize falsy exc_info values --- Lib/logging/__init__.py | 2 ++ .../Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 549a6b3c457b2c..2924ecdfbe204f 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1680,6 +1680,8 @@ def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False, exc_info = (type(exc_info), exc_info, exc_info.__traceback__) elif not isinstance(exc_info, tuple): exc_info = sys.exc_info() + else: + exc_info = None record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra, sinfo) self.handle(record) diff --git a/Misc/NEWS.d/next/Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst b/Misc/NEWS.d/next/Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst new file mode 100644 index 00000000000000..fece3ae737cd64 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst @@ -0,0 +1,5 @@ +The log functions in the :mod:`logging` module and the +:class:`logging.Logger` class now normalize falsy ``exc_info`` arguments to +``None`` before passing them to :meth:`logging.Logger.makeRecord` and +subsequently to :class:`logging.LogRecord`. This aligns +:attr:`logging.LogRecord.exc_info` with the documentation. From 96073f80fe3e908ce5c35dcda4f5c4164f8c7bfb Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Mon, 5 Oct 2026 15:53:16 +0200 Subject: [PATCH 2/2] Fix unknown reference target --- .../next/Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst b/Misc/NEWS.d/next/Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst index fece3ae737cd64..9bdf648f42783f 100644 --- a/Misc/NEWS.d/next/Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst +++ b/Misc/NEWS.d/next/Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst @@ -2,4 +2,4 @@ The log functions in the :mod:`logging` module and the :class:`logging.Logger` class now normalize falsy ``exc_info`` arguments to ``None`` before passing them to :meth:`logging.Logger.makeRecord` and subsequently to :class:`logging.LogRecord`. This aligns -:attr:`logging.LogRecord.exc_info` with the documentation. +``logging.LogRecord.exc_info`` with the documentation.