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

Bare except: usages in turtle.py #71425

Closed
JelleZijlstra opened this issue Jun 6, 2016 · 11 comments
Closed

Bare except: usages in turtle.py #71425

JelleZijlstra opened this issue Jun 6, 2016 · 11 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@JelleZijlstra
Copy link
Member

BPO 27238
Nosy @brettcannon, @terryjreedy, @vadmium, @serhiy-storchaka, @JelleZijlstra
Files
  • issue27238.patch
  • issue27238-cr.patch: revised patch
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2016-06-14.19:55:39.216>
    created_at = <Date 2016-06-06.00:38:06.281>
    labels = ['type-bug', 'library']
    title = 'Bare except: usages in turtle.py'
    updated_at = <Date 2016-06-14.19:55:39.215>
    user = 'https://github.com/JelleZijlstra'

    bugs.python.org fields:

    activity = <Date 2016-06-14.19:55:39.215>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-06-14.19:55:39.216>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2016-06-06.00:38:06.281>
    creator = 'JelleZijlstra'
    dependencies = []
    files = ['43258', '43299']
    hgrepos = []
    issue_num = 27238
    keywords = ['patch']
    message_count = 11.0
    messages = ['267493', '267528', '267556', '267562', '267570', '267592', '267779', '268167', '268583', '268584', '268585']
    nosy_count = 6.0
    nosy_names = ['brett.cannon', 'terry.reedy', 'python-dev', 'martin.panter', 'serhiy.storchaka', 'JelleZijlstra']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27238'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6']

    @JelleZijlstra
    Copy link
    Member Author

    Will add a patch

    @JelleZijlstra JelleZijlstra self-assigned this Jun 6, 2016
    @JelleZijlstra JelleZijlstra added the stdlib Python modules in the Lib dir label Jun 6, 2016
    @JelleZijlstra
    Copy link
    Member Author

    This patch removes all usages of "except:" in turtle.py. The tests in test_turtle.py and turtle.rst still work.

    @serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Jun 6, 2016
    @serhiy-storchaka
    Copy link
    Member

    Brett, can __file__ of imported/executed module be None, bytes or absent in 3.6? Can it be non-str?

    @brettcannon
    Copy link
    Member

    __file__ could be None if __spec__.origin is None. The import machinery doesn't introspect on __file__ for anything, so it won't break import if __file__ has alternative values. In general, though, normal imports will set __file__ to a string.

    @vadmium
    Copy link
    Member

    vadmium commented Jun 6, 2016

    The documentation says __file__ can be missing. It is missing for builtin modules (e.g. sys) and frozen modules (e.g. __hello__).

    @serhiy-storchaka
    Copy link
    Member

    Thanks Brett and Martin.

    Jelle, I think it would be safer to use "except Exception" here. "except (TypeError, ValueError):" is not enough.

    @JelleZijlstra
    Copy link
    Member Author

    Thanks for the review and comments. This patch addresses your comments and changes the __file__-related one to catch Exception.

    @terryjreedy
    Copy link
    Member

    Add a comment to indicate that bare exception is intentional and briefly why.

    @serhiy-storchaka
    Copy link
    Member

    LGTM.

    There is no case for bare except here. Actually it is a bug, since (in this file) a bare except can swallow KeyboardInterrupt.

    @serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error and removed type-feature A feature request or enhancement labels Jun 14, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 14, 2016

    New changeset 78e5efa3dd9e by Serhiy Storchaka in branch '3.5':
    Issue bpo-27238: Got rid of bare excepts in the turtle module. Original patch
    https://hg.python.org/cpython/rev/78e5efa3dd9e

    New changeset e9d023b7d676 by Serhiy Storchaka in branch '2.7':
    Issue bpo-27238: Got rid of bare excepts in the turtle module. Original patch
    https://hg.python.org/cpython/rev/e9d023b7d676

    New changeset cd68cf41adf2 by Serhiy Storchaka in branch 'default':
    Issue bpo-27238: Got rid of bare excepts in the turtle module. Original patch
    https://hg.python.org/cpython/rev/cd68cf41adf2

    @serhiy-storchaka
    Copy link
    Member

    Thank you for your contribution Jelle.

    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants