You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
__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.
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.