Title: gh-161918: Correct the documented type of `LogRecord`'s `exc_info` parameter by SelmanBoray · Pull Request #162179 · python/cpython · GitHub
Open Graph Title: gh-161918: Correct the documented type of `LogRecord`'s `exc_info` parameter by SelmanBoray · Pull Request #162179 · python/cpython
X Title: gh-161918: Correct the documented type of `LogRecord`'s `exc_info` parameter by SelmanBoray · Pull Request #162179 · python/cpython
Description: The LogRecord documentation gives the type of exc_info as tuple[type[BaseException], BaseException, types.TracebackType] | None. As reported in #161918, records created by the normal logging methods can hold two shapes that this type excludes:
logger.error("msg", exc_info=True) outside an except block stores (None, None, None), because Logger._log() passes on what sys.exc_info() returns.
logger.error("msg", exc_info=ValueError()) stores a tuple whose traceback is None, because the exception was never raised.
This changes the documented type to tuple[type[BaseException], BaseException, types.TracebackType | None] | tuple[None, None, None] | None. That is what Logger._log() produces on main, it agrees with the adjacent description ("as returned by sys.exc_info()"), and it matches the typeshed annotation.
Documentation only, one line, no behaviour change. This covers only the LogRecord parameter type. The other questions in #161918 (what makeLogRecord() and Logger.makeRecord() accept, Formatter.formatException(), stack_info) are not addressed, so this does not close the issue. The exc_info row of the "LogRecord attributes" table is left as it is.
Checks, on Windows with Python 3.12.10:
HTML build of Doc/ with Sphinx 9.1.1 (dependencies from Doc/requirements.txt, options --nitpicky --keep-going): the build succeeds with no warnings for library/logging.rst, and the rendered parameter shows the full type. The only warnings in the full build are nitpicky missing-reference warnings in other files.
sphinx-lint --enable=default-role (1.0.2) on Doc/library/logging.rst: no problems found.
The reproduction from the issue, run on Python 3.12.10, prints (None, None, None) and (
Open Graph Description: The LogRecord documentation gives the type of exc_info as tuple[type[BaseException], BaseException, types.TracebackType] | None. As reported in #161918, records created by the normal logging method...
X Description: The LogRecord documentation gives the type of exc_info as tuple[type[BaseException], BaseException, types.TracebackType] | None. As reported in #161918, records created by the normal logging method...
Opengraph URL: https://github.com/python/cpython/pull/162179
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:917a2047-2dba-acfb-7b1e-678b1a48228c |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B0FA:1AD4B2:77096:A20CB:6B0018E8 |
| html-safe-nonce | 8cbf0a86447ff07f6dc49f3543ae51b29efa661e2beb5a39cffd8d67798b489d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMEZBOjFBRDRCMjo3NzA5NjpBMjBDQjo2QjAwMThFOCIsInZpc2l0b3JfaWQiOiI3NTA0NjQ0MDIzNjQzMDE5NDk2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ecc58d9b7bbb46eb3de9cb6a88086f9f917c14b51ff03d6bc097039f0b6c3a44 |
| hovercard-subject-tag | pull_request:5365890262 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/162179/files |
| twitter:image | https://avatars.githubusercontent.com/u/237838469?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/237838469?s=400&v=4 |
| og:image:alt | The LogRecord documentation gives the type of exc_info as tuple[type[BaseException], BaseException, types.TracebackType] | None. As reported in #161918, records created by the normal logging method... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | a2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 70121d4e855ee0bb7b75cf15d061d91f8863c0f8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width