This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: document BaseException in favour of bare except in error tutorial
Type: Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, graingert, lukasz.langa, miss-islington, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2020-08-18 10:56 by graingert, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 21917 merged graingert, 2020-08-18 10:56
PR 27646 merged miss-islington, 2021-08-06 20:44
Messages (9)
msg375608 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-08-18 11:10
What a problem do you try to solve? What is wrong with the current documentation?
msg375609 - (view) Author: Thomas Grainger (graingert) * Date: 2020-08-18 11:11
it seems odd to document digging around in sys.exc_info() in favour of the more ergonomic syntax to do the same thing
msg375773 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-08-21 22:35
PEP 8 discourages the use of bare except.
msg375782 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-08-22 05:21
It is a tutorial. The purpose of this part is documenting the bare except clause. It cannot be done without using a bare except in example.

There is nothing wrong with a bare except if it used properly (e.g. if the caught exception is reraised). In any case "except BaseException" is not any better, because it is equivalent to a bare except.

Note also that PR 21917 introduces an error: instead of printing the type of exception it prints the stringified exception itself (in some case it is an empty string).
msg375793 - (view) Author: Thomas Grainger (graingert) * Date: 2020-08-22 10:01
The purpose of this tutorial section is to document how to catch all types of exceptions and extract the type and value. When this is required, `BaseException as err:` is the preferred approach.

This document still mentions the alternative approach so that readers will know what it means when they encounter it, and know to upgrade it to the py2.4+ syntax
msg396976 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-07-05 09:06
Serhiy/Terry: Is further discussion needed? Can this be closed, or should the proposed PR be applied (after resolving any issues)?
msg399145 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-08-06 20:44
New changeset e9a6f1b78bf57d9f3f99547bd007d7cfc9724cfb by Thomas Grainger in branch 'main':
bpo-41576: document BaseException in favor of bare except (GH-21917)
https://github.com/python/cpython/commit/e9a6f1b78bf57d9f3f99547bd007d7cfc9724cfb
msg399151 - (view) Author: miss-islington (miss-islington) Date: 2021-08-06 21:14
New changeset 699ee016af5736ffc80f68359617611a22b72943 by Miss Islington (bot) in branch '3.10':
bpo-41576: document BaseException in favor of bare except (GH-21917)
https://github.com/python/cpython/commit/699ee016af5736ffc80f68359617611a22b72943
msg399152 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-08-06 21:15
Thanks, Thomas! ✨ 🍰 ✨
History
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85748
2021-08-06 21:15:38lukasz.langasetstatus: open -> closed
versions: + Python 3.10, Python 3.11
messages: + msg399152

resolution: fixed
stage: patch review -> resolved
2021-08-06 21:14:43miss-islingtonsetmessages: + msg399151
2021-08-06 20:56:39erlendaaslandsetnosy: - erlendaasland
2021-08-06 20:44:24lukasz.langasetnosy: + lukasz.langa
messages: + msg399145
2021-08-06 20:44:22miss-islingtonsetkeywords: + patch
nosy: + miss-islington

pull_requests: + pull_request26140
stage: patch review
2021-07-05 09:06:48erlendaaslandsetnosy: + erlendaasland
messages: + msg396976
2020-08-22 10:01:41graingertsetmessages: + msg375793
2020-08-22 05:21:07serhiy.storchakasetmessages: + msg375782
2020-08-21 22:35:14terry.reedysetnosy: + terry.reedy
messages: + msg375773
2020-08-18 11:11:52graingertsetmessages: + msg375609
2020-08-18 11:10:08serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg375608
2020-08-18 10:56:07graingertcreate