Skip to content

Commit 938144e

Browse files
srittauvsajip
andauthored
gh-158839: Normalize falsy exc_info values in LogRecord (GH-158840)
Co-authored-by: Vinay Sajip <vinay_sajip@yahoo.co.uk>
1 parent 3646ea5 commit 938144e

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎Lib/logging/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,6 +1680,8 @@ def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False,
16801680
exc_info = (type(exc_info), exc_info, exc_info.__traceback__)
16811681
elif not isinstance(exc_info, tuple):
16821682
exc_info = sys.exc_info()
1683+
else: # Normalize any falsy value to None, for type precision
1684+
exc_info = None
16831685
record = self.makeRecord(self.name, level, fn, lno, msg, args,
16841686
exc_info, func, extra, sinfo)
16851687
self.handle(record)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The log functions in the :mod:`logging` module and the
2+
:class:`logging.Logger` class now normalize falsy ``exc_info`` arguments to
3+
``None`` before passing them to :meth:`logging.Logger.makeRecord` and
4+
subsequently to :class:`logging.LogRecord`. This aligns
5+
``logging.LogRecord.exc_info`` with the documentation.

0 commit comments

Comments
 (0)