[issue26637] importlib: better error message when import fail during Python shutdown

2016-03-25 Thread Roundup Robot

Roundup Robot added the comment:

New changeset e2c482b60776 by Victor Stinner in branch 'default':
Issue #26637: Fix test_io
https://hg.python.org/cpython/rev/e2c482b60776

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26637] importlib: better error message when import fail during Python shutdown

2016-03-24 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 14c56f697a85 by Victor Stinner in branch 'default':
Fix bug in __import__ during Python shutdown
https://hg.python.org/cpython/rev/14c56f697a85

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26637] importlib: better error message when import fail during Python shutdown

2016-03-24 Thread STINNER Victor

Changes by STINNER Victor :


--
resolution:  -> fixed
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26637] importlib: better error message when import fail during Python shutdown

2016-03-24 Thread STINNER Victor

STINNER Victor added the comment:

> It's technically a change in semantics as it shifts what exception is raised, 
> so I wouldn't backport it.

Ok, I'm fine with only changing Python 3.6.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26637] importlib: better error message when import fail during Python shutdown

2016-03-24 Thread Brett Cannon

Brett Cannon added the comment:

It's technically a change in semantics as it shifts what exception is raised, 
so I wouldn't backport it.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26637] importlib: better error message when import fail during Python shutdown

2016-03-24 Thread STINNER Victor

STINNER Victor added the comment:

Oh. And is it ok to apply this change to Python 2.7 and 3.5?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26637] importlib: better error message when import fail during Python shutdown

2016-03-24 Thread STINNER Victor

STINNER Victor added the comment:

I will reply to my own question: in fact, ImportError is more convenient. The 
"try/except ImportError" pattern is common, in some cases, it's acceptable to 
skip a whole module. For a direct example on import during Python shutdown, see 
the issue #21925: "ResourceWarning sometimes doesn't display" which adds 
"try/except ImportError" to be able to log warnings.

@Brett, Eric: So, do you like importlib_shutdown-2.patch?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26637] importlib: better error message when import fail during Python shutdown

2016-03-24 Thread Brett Cannon

Brett Cannon added the comment:

Either ImportError or TypeError. ImportError makes sense since this is directly 
related to import semantics while TypeError makes sense as we are saying None 
specifically is not allowed.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26637] importlib: better error message when import fail during Python shutdown

2016-03-24 Thread STINNER Victor

STINNER Victor added the comment:

Updated patch with a dot in the comment :-)

Is ImportError the best exception in this case?

--
Added file: http://bugs.python.org/file42277/importlib_shutdown-2.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26637] importlib: better error message when import fail during Python shutdown

2016-03-24 Thread STINNER Victor

New submission from STINNER Victor:

Example of script.py:
-
class Bla:
def __del__(self):
try:
import 
except Exception as exc:
print("import error: [%s] %r" % (type(exc), exc))

bla = Bla()
-

Running this example logs a strange error:
-
$ python3.5 script.py
import error: [] TypeError("'NoneType' object is not 
iterable",)
-

The error comes from importlib._bootstrap._find_spec() which tries to iterator 
on sys.meta_path, whereas PyImport_Cleanup() was called and this function 
setted sys.meta_path to None.

Attached patch enhances _find_spec() to handle this case to return None. Error 
with the patch:
-
$ python3.5 script.py
import error: [] ImportError('sys.meta_path is None, 
Python is likely shutting down',)
-

--
components: Library (Lib)
files: importlib_shutdown.patch
keywords: patch
messages: 262352
nosy: brett.cannon, eric.snow, haypo
priority: normal
severity: normal
status: open
title: importlib: better error message when import fail during Python shutdown
versions: Python 2.7, Python 3.5, Python 3.6
Added file: http://bugs.python.org/file42275/importlib_shutdown.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com