[issue29851] Have importlib.reload() raise ImportError when a spec can't be found

2017-04-03 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Wouldn't ModuleNotFoundError be more appropriate?

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue29851] Have importlib.reload() raise ImportError when a spec can't be found

2017-04-03 Thread Garvit Khatri

Changes by Garvit Khatri :


--
pull_requests: +1149

___
Python tracker 

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



[issue29851] Have importlib.reload() raise ImportError when a spec can't be found

2017-03-20 Thread Brett Cannon

Brett Cannon added the comment:

First, I don't know what version you're testing against because 3.0.6.1 isn't 
an actual release of Python and 3.6.1 isn't released yet (unless you know 
something I don't know :) ).

Second, the issue is that you're trying to import a module under a name which 
doesn't match the file specified. That's causing reload() to not be able to 
find the original source file to reload against, leading to the None being 
returned by importlib._bootstrap._find_spec() which is leading to the error 
you're seeing. (Remember, reload() basically runs like an import statement for 
the module you're reloading but recycles the module object.)

Third, while an exception is reasonable in this case, it is misleading and 
reload() should be updated to raise an ImportError if _bootstrap._find_spec() 
returns None.

I'm marking this issue as an easy fix since you just need to add an `is None` 
check on a return value and then raise ImportError if necessary in case someone 
wants to propose a PR to improve the error. It will require a doc update to 
document the change in the exception raised.

--
keywords: +easy
nosy: +brett.cannon, eric.snow, ncoghlan
priority: normal -> low
title: importlib.reload references None object -> Have importlib.reload() raise 
ImportError when a spec can't be found
type: crash -> enhancement
versions: +Python 3.7

___
Python tracker 

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