Bug report
Pointed out by @tjkuson in python/typeshed#16466
According to the documentation, the exc_info argument to the log() group of function can be any falsy value to indicate that no exception information is provided. It's common to use either None or False here.
When a truthy value is provided, it is normalized to an exception info tuple before passing it to LogRecord. A falsy value is passed on unchanged:
|
if exc_info: |
|
if isinstance(exc_info, BaseException): |
|
exc_info = (type(exc_info), exc_info, exc_info.__traceback__) |
|
elif not isinstance(exc_info, tuple): |
|
exc_info = sys.exc_info() |
This contradicts LogRecords documentation, which says that only None is accepted and that the exc_info field can be a tuple or None. The mypy primer run in python/typeshed#16466 shows that a few projects make this assumption. For example, sphinx:
if record.exc_info is not None:
raise SphinxWarning(message) from record.exc_info[1]
Solution: Normalize falsy values to None before passing them to makeRecord.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
Bug report
Pointed out by @tjkuson in python/typeshed#16466
According to the documentation, the
exc_infoargument to thelog()group of function can be any falsy value to indicate that no exception information is provided. It's common to use eitherNoneorFalsehere.When a truthy value is provided, it is normalized to an exception info tuple before passing it to
LogRecord. A falsy value is passed on unchanged:cpython/Lib/logging/__init__.py
Lines 1678 to 1682 in 9112dae
This contradicts LogRecords documentation, which says that only
Noneis accepted and that theexc_infofield can be a tuple orNone. The mypy primer run in python/typeshed#16466 shows that a few projects make this assumption. For example, sphinx:Solution: Normalize falsy values to
Nonebefore passing them tomakeRecord.CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
exc_infovalues inLogRecord#158840