New submission from Arfrever Frehtes Taifersar Arahesis 
<arfrever....@gmail.com>:

If, after building of Python, libexpat.so (library used by pyexpat module) has 
been broken/removed or pyexpat module has been broken/removed, then attempt of 
import of _elementtree module, which requires pyexpat module, will raise 
strange exceptions in Python 3.

These exceptions can be simulated by setting sys.modules["pyexpat"] = None.

$ python2.6 -c 'import sys; sys.modules["pyexpat"] = None; import _elementtree'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named pyexpat
$ python2.7 -c 'import sys; sys.modules["pyexpat"] = None; import _elementtree'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: PyCapsule_Import could not import module "pyexpat"
$ python3.1 -c 'import sys; sys.modules["pyexpat"] = None; import _elementtree'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
SystemError: initialization of _elementtree raised unreported exception
$ python3.2 -c 'import sys; sys.modules["pyexpat"] = None; import _elementtree'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
SystemError: initialization of _elementtree raised unreported exception
$ python3.3 -c 'import sys; sys.modules["pyexpat"] = None; import _elementtree'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1286, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1253, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 432, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 347, in set_package_wrapper
  File "<frozen importlib._bootstrap>", line 360, in set_loader_wrapper
  File "<frozen importlib._bootstrap>", line 870, in load_module
RuntimeError: cannot load dispatch table from pyexpat

I suggest to raise ImportError instead of SystemError or RuntimeError.
Third-party modules would rather use only 'except ImportError: pass' instead of 
'except (ImportError, SystemError, RuntimeError): pass' when trying to 
optionally use e.g. xml.etree.cElementTree.
xml.etree.ElementTree in Python 3.3 also ignores only ImportError when trying 
to import _elementtree.

----------
messages: 162198
nosy: Arfrever, eli.bendersky, flox
priority: normal
severity: normal
status: open
title: _elementtree: Raise ImportError when importing of pyexpat fails
versions: Python 3.2, Python 3.3

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue14988>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to