Raise TypeError if the name given to importlib.__import__() lacks an rpartition
attribute. Was throwing AttributeError before. Discovered when running
test_builtin against importlib.
This exception change is specific to importlib.__import__() and does not apply to
import_module() as it is being done for compatibility reasons only.
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 95fea33..063f603 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -917,6 +917,8 @@
import (e.g. ``from ..pkg import mod`` would have a 'level' of 2).
"""
+ if not hasattr(name, 'rpartition'):
+ raise TypeError("module name must be str, not {}".format(type(name)))
if level == 0:
module = _gcd_import(name)
else: