Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document BaseException in favour of bare except in error tutorial #85748

Closed
graingert mannequin opened this issue Aug 18, 2020 · 9 comments
Closed

document BaseException in favour of bare except in error tutorial #85748

graingert mannequin opened this issue Aug 18, 2020 · 9 comments
Labels
3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir

Comments

@graingert
Copy link
Mannequin

graingert mannequin commented Aug 18, 2020

BPO 41576
Nosy @terryjreedy, @ambv, @serhiy-storchaka, @graingert, @miss-islington
PRs
  • bpo-41576: document BaseException in favor of bare except #21917
  • [3.10] bpo-41576: document BaseException in favor of bare except (GH-21917) #27646
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-08-06.21:15:38.214>
    created_at = <Date 2020-08-18.10:56:07.233>
    labels = ['3.11', '3.10', 'docs']
    title = 'document BaseException in favour of bare except in error tutorial'
    updated_at = <Date 2021-08-06.21:15:38.213>
    user = 'https://github.com/graingert'

    bugs.python.org fields:

    activity = <Date 2021-08-06.21:15:38.213>
    actor = 'lukasz.langa'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2021-08-06.21:15:38.214>
    closer = 'lukasz.langa'
    components = ['Documentation']
    creation = <Date 2020-08-18.10:56:07.233>
    creator = 'graingert'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41576
    keywords = ['patch']
    message_count = 9.0
    messages = ['375608', '375609', '375773', '375782', '375793', '396976', '399145', '399151', '399152']
    nosy_count = 6.0
    nosy_names = ['terry.reedy', 'docs@python', 'lukasz.langa', 'serhiy.storchaka', 'graingert', 'miss-islington']
    pr_nums = ['21917', '27646']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue41576'
    versions = ['Python 3.10', 'Python 3.11']

    @graingert graingert mannequin assigned docspython Aug 18, 2020
    @graingert graingert mannequin added the docs Documentation in the Doc dir label Aug 18, 2020
    @graingert graingert mannequin assigned docspython Aug 18, 2020
    @graingert graingert mannequin added the docs Documentation in the Doc dir label Aug 18, 2020
    @serhiy-storchaka
    Copy link
    Member

    What a problem do you try to solve? What is wrong with the current documentation?

    @graingert
    Copy link
    Mannequin Author

    graingert mannequin commented Aug 18, 2020

    it seems odd to document digging around in sys.exc_info() in favour of the more ergonomic syntax to do the same thing

    @terryjreedy
    Copy link
    Member

    PEP-8 discourages the use of bare except.

    @serhiy-storchaka
    Copy link
    Member

    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).

    @graingert
    Copy link
    Mannequin Author

    graingert mannequin commented Aug 22, 2020

    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

    @erlend-aasland
    Copy link
    Contributor

    Serhiy/Terry: Is further discussion needed? Can this be closed, or should the proposed PR be applied (after resolving any issues)?

    @ambv
    Copy link
    Contributor

    ambv commented Aug 6, 2021

    New changeset e9a6f1b by Thomas Grainger in branch 'main':
    bpo-41576: document BaseException in favor of bare except (GH-21917)
    e9a6f1b

    @miss-islington
    Copy link
    Contributor

    New changeset 699ee01 by Miss Islington (bot) in branch '3.10':
    bpo-41576: document BaseException in favor of bare except (GH-21917)
    699ee01

    @ambv
    Copy link
    Contributor

    ambv commented Aug 6, 2021

    Thanks, Thomas! ✨ 🍰 ✨

    @ambv ambv added 3.10 only security fixes 3.11 only security fixes labels Aug 6, 2021
    @ambv ambv closed this as completed Aug 6, 2021
    @ambv ambv added 3.10 only security fixes 3.11 only security fixes labels Aug 6, 2021
    @ambv ambv closed this as completed Aug 6, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes 3.11 only security fixes docs Documentation in the Doc dir
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants