Skip to content

Bare except: usages in turtle.py #71425

Closed

Description

@JelleZijlstra
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']

    Activity

    1. JelleZijlstra commented on Jun 6, 2016

      @JelleZijlstra
      MemberAuthor

      Will add a patch

    2. self-assigned this
      on Jun 6, 2016
    3. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Jun 6, 2016
    4. JelleZijlstra commented on Jun 6, 2016

      @JelleZijlstra
      MemberAuthor

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

    5. serhiy-storchaka commented on Jun 6, 2016

      @serhiy-storchaka
      Member

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

    6. brettcannon commented on Jun 6, 2016

      @brettcannon
      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.

    7. vadmium commented on Jun 6, 2016

      @vadmium
      Member

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

    8. serhiy-storchaka commented on Jun 7, 2016

      @serhiy-storchaka
      Member

      Thanks Brett and Martin.

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

    9. JelleZijlstra commented on Jun 8, 2016

      @JelleZijlstra
      MemberAuthor

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

    10. terryjreedy commented on Jun 10, 2016

      @terryjreedy
      Member

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

    11. serhiy-storchaka commented on Jun 14, 2016

      @serhiy-storchaka
      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.

    12. added
      type-bugAn unexpected behavior, bug, or error
      and removed
      type-featureA feature request or enhancement
      on Jun 14, 2016
    13. python-dev commented on Jun 14, 2016

      python-devmannequin
      Mannequin

      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

    14. serhiy-storchaka commented on Jun 14, 2016

      @serhiy-storchaka
      Member

      Thank you for your contribution Jelle.

    15. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions