classification
Title: pkgutil.get_loader() fails on "__main__"
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, eric.snow, larry, ncoghlan, python-dev
Priority: release blocker Keywords: 3.4regression, patch

Created on 2014-04-11 14:07 by eric.snow, last changed 2014-04-19 06:20 by eric.snow. This issue is now closed.

Files
File name Uploaded Description Edit
issue21200-pkgutil-main.diff eric.snow, 2014-04-14 01:16 review
Messages (5)
msg215926 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2014-04-11 14:07
Prior to 3.4, pkgutil.get_loader('__main__') would return None.  Now it results in an ImportError.  That's because it calls importlib.util.find_spec() which fails if an existing module does not have __spec__ or it is None.
msg216043 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2014-04-14 01:16
Here's a patch that checks for modules that don't have __spec__ set.

The patch will fix the problem.  However note that the docs and docstring imply (to me) that we should turn any ImportError coming out of the find_loader() call into returning None.  Fixing that will also fix this bug, so this patch may be unnecessary.
msg216048 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2014-04-14 01:49
I've opened #21211 to more directly address the find_loader() issue.
msg216847 - (view) Author: Roundup Robot (python-dev) Date: 2014-04-19 06:17
New changeset bc4eb1b3db5d by Eric Snow in branch '3.4':
Issue #21200: Return None from pkgutil.get_loader() when __spec__ is missing.
http://hg.python.org/cpython/rev/bc4eb1b3db5d
msg216848 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2014-04-19 06:20
The change is pretty minor so I went ahead and pushed it.  To be honest, we should consider deprecating both get_loader and find_loader.  I'm just not going to worry about it right now. :)
History
Date User Action Args
2014-04-19 06:20:35eric.snowsetstatus: open -> closed
resolution: fixed
messages: + msg216848

stage: patch review -> resolved
2014-04-19 06:17:48python-devsetnosy: + python-dev
messages: + msg216847
2014-04-14 01:49:36eric.snowsetmessages: + msg216048
2014-04-14 01:16:55eric.snowsetfiles: + issue21200-pkgutil-main.diff
keywords: + patch
messages: + msg216043

stage: test needed -> patch review
2014-04-11 14:07:35eric.snowcreate