New submission from Anders Hammarquist <i...@iko.pp.se>:

When testing Eutaxia on PyPy (1.9) I discovered a discrepancy in the path_hooks 
import hook implementation. In CPython (2.7), if the find_module() method 
raises ImportError (as imp.find_module() does when it does not find a module in 
the given path), will cause the search to continue, whereas PyPy would 
propagate the ImportError.

PyPy has now been changed to behave like CPython.

The documentation is not entirely clear, but it does not explicitly document 
the import hook mechanism as eating an ImportError in find_module(). It should 
probably be made explicit, which ever way it should be. It is not obvious what 
is the correct behaviour, given the implicit relative imports, where the 
ImportError simply means that the import hook cannot find the module.

Quick testing on CPython 3.3 indicates that it behaves like PyPy did, but as it 
doesn't do implicit relative imports my test case didn't work as it was. For 
3.3, without implicit relative imports, propagating the ImportError feels like 
the correct behaviour.

The attached demonstration needs a file /tmp/test/foo.py that does a top-level 
import, e.g. "import errno" to demonstrate the discrepancy.

----------
assignee: docs@python
components: Documentation
files: testimport.py
messages: 164998
nosy: docs@python, iko
priority: normal
severity: normal
status: open
title: import hook behavior documentation improvement
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file26315/testimport.py

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

Reply via email to