Fix TypeError crash on failed imports under py3.3.

Starting with Python 3.3, NamespacePath passed to importlib hooks
seem to have lost the ability to be accessed by index.

We wrap the index access in a try..except and wrap the path in a
list if it happens.

Fixes #383.
This commit is contained in:
Virgil Dupras 2013-11-08 16:59:13 -05:00
parent a9d1f40c29
commit ded88700a3
1 changed files with 6 additions and 1 deletions

View File

@ -57,7 +57,12 @@ class AssertionRewritingHook(object):
lastname = names[-1] lastname = names[-1]
pth = None pth = None
if path is not None and len(path) == 1: if path is not None and len(path) == 1:
pth = path[0] try:
pth = path[0]
except TypeError:
# Starting with Python 3.3, `path` started being unsubscriptable, we have to wrap it
# in a list.
pth = list(path)[0]
if pth is None: if pth is None:
try: try:
fd, fn, desc = imp.find_module(lastname, path) fd, fn, desc = imp.find_module(lastname, path)