]> granicus.if.org Git - python/commitdiff
Do a type check instead of an interface check.
authorBrett Cannon <brett@python.org>
Thu, 23 Feb 2012 23:18:48 +0000 (18:18 -0500)
committerBrett Cannon <brett@python.org>
Thu, 23 Feb 2012 23:18:48 +0000 (18:18 -0500)
Lib/importlib/_bootstrap.py

index 6c4367fde9644bc0be7f716d31b897df8a5012a9..6382079c19b8108c70eb11245a243f9928372799 100644 (file)
@@ -920,12 +920,12 @@ def _find_module(name, path):
 
 def _sanity_check(name, package, level):
     """Verify arguments are "sane"."""
-    if not hasattr(name, 'rpartition'):
+    if not isinstance(name, str):
         raise TypeError("module name must be str, not {}".format(type(name)))
     if level < 0:
         raise ValueError('level must be >= 0')
     if package:
-        if not hasattr(package, 'rindex'):
+        if not isinstance(package, str):
             raise ValueError("__package__ not set to a string")
         elif package not in sys.modules:
             msg = ("Parent module {0!r} not loaded, cannot perform relative "