Bare except: usages in turtle.py #71425
Copy link
Copy link
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
| BPO | 27238 |
|---|---|
| Nosy | @brettcannon, @terryjreedy, @vadmium, @serhiy-storchaka, @JelleZijlstra |
| Files |
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']Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
JelleZijlstra commentedon Jun 6, 2016
Will add a patch
JelleZijlstra commentedon Jun 6, 2016
This patch removes all usages of "except:" in turtle.py. The tests in test_turtle.py and turtle.rst still work.
serhiy-storchaka commentedon Jun 6, 2016
Brett, can __file__ of imported/executed module be None, bytes or absent in 3.6? Can it be non-str?
brettcannon commentedon Jun 6, 2016
__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 commentedon 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 commentedon Jun 7, 2016
Thanks Brett and Martin.
Jelle, I think it would be safer to use "except Exception" here. "except (TypeError, ValueError):" is not enough.
JelleZijlstra commentedon Jun 8, 2016
Thanks for the review and comments. This patch addresses your comments and changes the __file__-related one to catch Exception.
terryjreedy commentedon Jun 10, 2016
Add a comment to indicate that bare exception is intentional and briefly why.
serhiy-storchaka commentedon Jun 14, 2016
LGTM.
There is no case for bare except here. Actually it is a bug, since (in this file) a bare except can swallow KeyboardInterrupt.
python-dev commentedon 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 commentedon Jun 14, 2016
Thank you for your contribution Jelle.