Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`LogRecord` should normalize falsy `exc_info` values

Open Beginner friendly
#158,839 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start in Lib/logging/init.py at the logging call path cited in the issue, where exc_info is normalized before makeRecord. Check the relevant logging tests and add coverage for falsy exc_info values such as False and None. Done when falsy values reach LogRecord as None and the tests pass.

Written by the indexing model from the issue text.

Description

stdlib type-bug
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:

https://github.com/python/cpython/blob/9112daed900c3314fa522043fc64ddbb2ecd4ca5/Lib/logging/__init__.py#L1678-L1682

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
  • gh-158840
Dominant language
Python
Stars
77.6k
Forks
37.6k
Avg merge
1d 10h
Merged PRs (30d)
573

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python/cpython

All issues in python/cpython

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.