https://github.com/python/cpython/commit/938144efad4659f7aa66bf9ef362fd3c602c4bbc
commit: 938144efad4659f7aa66bf9ef362fd3c602c4bbc
branch: main
author: Sebastian Rittau <[email protected]>
committer: vsajip <[email protected]>
date: 2026-10-15T18:19:46+01:00
summary:

gh-158839: Normalize falsy `exc_info` values in `LogRecord` (GH-158840)

Co-authored-by: Vinay Sajip <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-10-05-14-58-12.gh-issue-158839.wYd6fI.rst
M Lib/logging/__init__.py

diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 549a6b3c457b2c6..15d5ac281791839 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:  # Normalize any falsy value to None, for type precision
+            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 000000000000000..9bdf648f42783f2
--- /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
+``logging.LogRecord.exc_info`` with the documentation.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to