[issue37444] Differing exception between builtins and importlib when importing beyond top-level package

Brett Cannon report at bugs.python.org
Wed Jan 22 13:36:49 EST 2020


Brett Cannon <brett at python.org> added the comment:

The problem with the hybrid exception is that importlib would then still raise a different exception from import itself, so the discrepancy would persist. And if you updated import you could then break people in another way where they were catching ValueError and ImportError separately for different cases and now they would potentially catch the wrong exception for that ValueError case.

Basically changing what exceptions get raised sucks as someone is almost inevitably broken. But since import and importlib strive to mirror each other as much as possible and be drop-in replacements, the consistency for the next 30 years of Python's life is more important I think than the case of:

1. Someone using importlib.import_module()
2. Who is specifically worried about relative imports going too far and no other import-related import and thus only catching ValueError and not ImportError
3. And are supporting older versions of Python
4. And will have a difficult time updating their `except` clause to now also capture ImportError

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37444>
_______________________________________


More information about the Python-bugs-list mailing list