Skip to content

Fix bare excepts in various places in std lib #60465

Closed

Description

@RamchandraApte
BPO 16261
Nosy @brettcannon, @terryjreedy, @vstinner, @ezio-melotti, @merwok, @asvetlov, @vadmium, @serhiy-storchaka
Files
  • patch.patch
  • bare_except.patch: Regenerated for Rietveld
  • 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 2015-05-20.07:35:47.678>
    created_at = <Date 2012-10-17.08:06:05.258>
    labels = ['type-bug', 'library']
    title = 'Fix bare excepts in various places in std lib'
    updated_at = <Date 2015-05-20.07:35:47.677>
    user = 'https://bugs.python.org/RamchandraApte'

    bugs.python.org fields:

    activity = <Date 2015-05-20.07:35:47.677>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-05-20.07:35:47.678>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2012-10-17.08:06:05.258>
    creator = 'Ramchandra Apte'
    dependencies = []
    files = ['28647', '28648']
    hgrepos = []
    issue_num = 16261
    keywords = ['patch']
    message_count = 20.0
    messages = ['173140', '173175', '174264', '174403', '174406', '174452', '174489', '174564', '174565', '179441', '179442', '179445', '179448', '179449', '179456', '202448', '216810', '243639', '243650', '243651']
    nosy_count = 11.0
    nosy_names = ['brett.cannon', 'terry.reedy', 'vstinner', 'ezio.melotti', 'eric.araujo', 'asvetlov', 'python-dev', 'sbt', 'Ramchandra Apte', 'martin.panter', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue16261'
    versions = ['Python 3.5']

    Activity

    1. RamchandraApte commented on Oct 17, 2012

      RamchandraAptemannequin
      MannequinAuthor

      Will attach patch.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Oct 17, 2012
    3. brettcannon commented on Oct 17, 2012

      @brettcannon
      Member

      One thing to be aware of, Ramchandra, is that there might be a slight backwards-compatibility problem from tightening up what exceptions propagate. Now with proper documentation and only applying things to 3.4 this probably won't be a problem.

    4. RamchandraApte commented on Oct 31, 2012

      RamchandraAptemannequin
      MannequinAuthor

      This seems quite difficult for one person;there are 589 lines having "except:"
      I'll work on the Tools directory.
      If anybody wants to help, please tell which folder you will do.

    5. asvetlov commented on Nov 1, 2012

      @asvetlov
      Contributor

      I'm pretty sure Doc and Lib are already fixed, only Tools left.

    6. RamchandraApte commented on Nov 1, 2012

      RamchandraAptemannequin
      MannequinAuthor

      On 1 November 2012 17:21, Andrew Svetlov <report@bugs.python.org> wrote:

      Andrew Svetlov added the comment:

      I'm pretty sure Doc and Lib are already fixed, only Tools left.

      ----------
      nosy: +asvetlov


      Python tracker <report@bugs.python.org>
      <http://bugs.python.org/issue16261\>


      No. 405 are there in Lib. Try running grep "except:" -R Lib --include "*.py" to see yourself.

    7. asvetlov commented on Nov 1, 2012

      @asvetlov
      Contributor

      Sorry, looks like I don't understood you correctly.
      Do you want to replace `except:` to `except Exception` or something else?

    8. RamchandraApte commented on Nov 2, 2012

      RamchandraAptemannequin
      MannequinAuthor

      Yes.
      most of the bare excepts can be replaced with a stricter clause

      On 2 November 2012 01:06, Andrew Svetlov <report@bugs.python.org> wrote:

      Andrew Svetlov added the comment:

      Sorry, looks like I don't understood you correctly.
      Do you want to replace `except:` to `except Exception` or something else?

      ----------


      Python tracker <report@bugs.python.org>
      <http://bugs.python.org/issue16261\>


    9. python-dev commented on Nov 2, 2012

      python-devmannequin
      Mannequin

      New changeset b2bd62d1644f by Andrew Svetlov in branch 'default':
      Issue bpo-16261: fix bare excepts in Doc/
      http://hg.python.org/cpython/rev/b2bd62d1644f

    10. asvetlov commented on Nov 2, 2012

      @asvetlov
      Contributor

      I've fixed bare except: in docs.
      Tomorrow we will have Python sprint in Kiev.
      Maybe somebody will take a look on Lib.

    11. RamchandraApte commented on Jan 9, 2013

      RamchandraAptemannequin
      MannequinAuthor

      Here's a patch on revision 75fe7f5fda9a (I did it on a trip without an internet connection)
      There might be some mistakes of this type:
      I incorrectly changed instances like this
      try: something except: close file raise
      to
      try: something finally: close file
      (the incorrect version closes the file always)

    12. RamchandraApte commented on Jan 9, 2013

      RamchandraAptemannequin
      MannequinAuthor

      Sorry, I entered the wrong filename for the patch and so it didn't get attached. Now I have attached it.

    13. serhiy-storchaka commented on Jan 9, 2013

      @serhiy-storchaka
      Member

      Unhappy Rietveld hasn't recognize your patch. I have regenerated it.

    14. sbt commented on Jan 9, 2013

      sbtmannequin
      Mannequin

      try:
      _MAXFD = os.sysconf("SC_OPEN_MAX")
      -except:
      +except ValueError:
      _MAXFD = 256

      os.sysconf() might raise OSError. I think ValueError is only raised if _SC_OPEN_MAX was undefined when the module was compiled.

    15. serhiy-storchaka commented on Jan 9, 2013

      @serhiy-storchaka
      Member

      See my comments on Rietveld.

    16. serhiy-storchaka commented on Jan 9, 2013

      @serhiy-storchaka
      Member

      Want to make a few warnings. Accepting your confirmation may take a long time. And it is very unlikely that your patch can be applied as a whole. The maintainers of the individual modules can apply it by parts.

    17. terryjreedy commented on Nov 8, 2013

      @terryjreedy
      Member

      The earlier bpo-15313 is about removing bare excepts in Idle code. These should be handled separately for two reasons.

      1. Changes can and in most cases should be backported.
      2. As with any other Python-coded application, uncaught exceptions cause Idle to quit. Currently, if Idle is started directly, rather than from a console, such an exit looks like a silent crash. So either the added tuple of exceptions to be caught must be complete, or the calling code must be adjusted.

      I copied the one idlelib fix (to PyShell.py) to that issue for separate examination. It should be removed from any patch applied here.

    18. terryjreedy commented on Apr 18, 2014

      @terryjreedy
      Member

      See more discussion on duplicate bpo-21259.

    19. vadmium commented on May 20, 2015

      @vadmium
      Member

      I reviewed the patch on Reitveld. All of the changes that do not have comments look okay to me, although some will definitely have merge conflicts with the current code. If someone updated the patch based on the comments, I think it may be okay to commit.

    20. python-dev commented on May 20, 2015

      python-devmannequin
      Mannequin

      New changeset b3a7215b9ce4 by Serhiy Storchaka in branch 'default':
      Issue bpo-16261: Converted some bare except statements to except statements
      https://hg.python.org/cpython/rev/b3a7215b9ce4

    21. serhiy-storchaka commented on May 20, 2015

      @serhiy-storchaka
      Member

      Resolved conflicts, fixed some noted issues in the patch and committed unquestionable changes. Thank you for your patch Ramchandra.

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