Brett Cannon added the comment:

It has nothing to do with runpy and __main__.py and everything to do with rev 
78619:0d52f125dd32 (which fixed issue #15715) which was done to ignore bogus 
names in fromlist. If you simply change the import line to "import foo.bar" 
then you get the expected result.

The options I see to solve this without invalidating issue #15715 is:

1) Parse the ImportError message to notice that it was a lookup failure and not 
some other ImportError (ewww)

2) Importlib has to tag every exception is raises because of a finder failure 
to know when an ImportError was triggered because the module wasn't found (less 
eww, but still brittle as it means only importlib or people aware of the flag 
will have the expected semantics)

3) Create a ModuleNotFoundError exception that subclasses ImportError and catch 
that (breaks doctests and introduces a new exception that people will need to 
be aware of, plus the question of whether it should just exist in importlib or 
be a builtin)

4) change importlib._bootstrap._handle_fromlist (and various other bits of 
importlib code) to call _find_module() and silently ignore when no finder is 
found as desired (probably need to add a flag to _find_and_load() to signal 
whether finder failure just returns None or raises ImportError)

While I prefer 3, I think it's a bit late in the release to try to introduce a 
new exception to begin separating the meaning of 16 different ``raise 
ImportError`` cases in importlib._bootstrap based on inheritance. My gut says 4 
is the best solution given the timeframe. I should be able to get a patch in on 
Friday if that works for people.

----------
assignee:  -> brett.cannon
priority: normal -> release blocker
stage:  -> test needed

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

Reply via email to