8000 IDLE - remove all bare excepts · Issue #59518 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

IDLE - remove all bare excepts #59518

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

Open
serwy mannequin opened this issue Jul 10, 2012 · 5 comments
Open

IDLE - remove all bare excepts #59518

serwy mannequin opened this issue Jul 10, 2012 · 5 comments
Assignees
Labels
topic-IDLE type-bug An unexpected behavior, bug, or error

Comments

@serwy
Copy link
Mannequin
serwy mannequin commented Jul 10, 2012
BPO 15313
Nosy @terryjreedy, @serwy

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/terryjreedy'
closed_at = None
created_at = <Date 2012-07-10.02:27:04.265>
labels = ['expert-IDLE', 'type-bug', '3.7']
title = 'IDLE - remove all bare excepts'
updated_at = <Date 2017-06-30.01:02:35.588>
user = 'https://github.com/serwy'

bugs.python.org fields:

activity = <Date 2017-06-30.01:02:35.588>
actor = 'terry.reedy'
assignee = 'terry.reedy'
closed = False
closed_date = None
closer = None
components = ['IDLE']
creation = <Date 2012-07-10.02:27:04.265>
creator = 'roger.serwy'
dependencies = []
files = []
hgrepos = []
issue_num = 15313
keywords = []
message_count = 5.0
messages = ['165145', '165157', '165162', '165163', '202449']
nosy_count = 2.0
nosy_names = ['terry.reedy', 'roger.serwy']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue15313'
versions = ['Python 3.6', 'Python 3.7']

@serwy serwy mannequin added type-feature A feature request or enhancement topic-IDLE labels Jul 10, 2012
@serwy
Copy link
Mannequin Author
serwy mannequin commented Jul 10, 2012

There are a lot of bare exceptions in IDLE. Here's the output of "grep -n 'except:' *.py"

AutoComplete.py:184: except:
AutoComplete.py:209: except:
Debugger.py:172: except:
Debugger.py:344: except:
EditorWindow.py:999: except:
ObjectBrowser.py:38: except:
ObjectBrowser.py:100: except:
PyShell.py:133: except: # but debugger may not be active right now....
PyShell.py:154: except:
PyShell.py:161: except:
PyShell.py:176: except:
PyShell.py:433: except:
PyShell.py:742: except:
PyShell.py:869: except:
PyShell.py:1043: except:
PyShell.py:1096: except:
PyShell.py:1193: except:
PyShell.py:1214: except:
PyShell.py:1245: except:
rpc.py:106: except:
rpc.py:206: except:
run.py:88: except:
run.py:120: except:
run.py:125: except:
run.py:248: except:
run.py:332: except:
SearchEngine.py:72: except:
StackViewer.py:66: except:
WindowList.py:47: except:

Slowly, these exceptions should be refined to include the exact exception being caught.

@terryjreedy
Copy link
Member

And possibly change the except clause. The except clause at PyShell 1245 was 'pass', which masked the issue of bpo-13532 and was changed to 'raise' to effectively remove the try: except: to make the unknown problem more visible. It should perhaps be really removed if and when all calls to PyShell.write(s) are properly guarded to make sure 's' is writable.

@terryjreedy terryjreedy added type-bug An unexpected behavior, bug, or error and removed type-feature A feature request or enhancement labels Jul 10, 2012
@serwy
Copy link
Mannequin Author
serwy mannequin commented Jul 10, 2012

Line 1245 is part of this code (in time, these line numbers will change.)

    try:
        self.text.mark_gravity("iomark", "right")
        OutputWindow.write(self, s, tags, "iomark")
        self.text.mark_gravity("iomark", "left")
    except:
        raise ###pass  # ### 11Aug07 KBK if we are expecting exceptions
                       \# let's find out what they are and be specific.

The delegator chain that sits between OutputWindow.write and the Tkinter text.insert method can raise any error. (The ColorDelegator would raise a TypeError when "s" was not a string). I'd rather not replace this with "except Exception:" since the delegators should catch their own errors.

I suggest removing this try/catch block.

@serwy
Copy link
Mannequin Author
serwy mannequin commented Jul 10, 2012

Also, bpo-13582 will become relevant on Windows since modifying the bare excepts may let uncaught exceptions be written to stderr, causing IDLE to crash.

@terryjreedy
Copy link
Member

RA's patch for bpo-16261 suggests

diff -r b76d2d8db81f Lib/idlelib/PyShell.py
--- a/Lib/idlelib/PyShell.py	Mon Dec 17 13:43:14 2012 +0530
+++ b/Lib/idlelib/PyShell.py	Wed Jan 09 19:10:26 2013 +0530
@@ -152,7 +152,7 @@
         lineno = int(float(text.index("insert")))
         try:
             self.breakpoints.remove(lineno)
-        except:
+        except ValueError:
             pass
         text.tag_remove("BREAK", "insert linestart",\
                         "insert lineend +1char")

@terryjreedy terryjreedy added the 3.7 (EOL) end of life label Jun 30, 2017
@terryjreedy terryjreedy self-assigned this Jun 30, 2017
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@terryjreedy terryjreedy removed the 3.7 (EOL) end of life label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-IDLE type-bug An unexpected behavior, bug, or error
Projects
Status: No status
Development

No branches or pull requests

1 participant
0