summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/__init__.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-02-07 01:15:27 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-02-07 01:15:27 (GMT)
commit2c318a1390e1a84c78d6f0cacaee1d21cc459234 (patch)
tree97f2579de870e21766febabe4acaaf53b8cd9eb9 /Lib/importlib/__init__.py
parent887b3f2625404f3835d47a63ae7e0ac4ee638cb6 (diff)
downloadcpython-2c318a1390e1a84c78d6f0cacaee1d21cc459234.zip
cpython-2c318a1390e1a84c78d6f0cacaee1d21cc459234.tar.gz
cpython-2c318a1390e1a84c78d6f0cacaee1d21cc459234.tar.bz2
Rewrite the code implementing __import__ for importlib. Now it is much simpler
and relies much more on meta path finders to abstract out various parts of import. As part of this the semantics for import_module tightened up and now follow __import__ much more closely (biggest thing is that the 'package' argument must now already be imported, else a SystemError is raised).
Diffstat (limited to 'Lib/importlib/__init__.py')
-rw-r--r--Lib/importlib/__init__.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py
index d3e7f8b..62e046e 100644
--- a/Lib/importlib/__init__.py
+++ b/Lib/importlib/__init__.py
@@ -29,7 +29,7 @@ def _set__import__():
"""Set __import__ to an instance of Import."""
global original__import__
original__import__ = __import__
- __builtins__['__import__'] = Import()
+ __builtins__['__import__'] = _bootstrap._import
def _reset__import__():
@@ -114,7 +114,7 @@ marshal._r_long = _r_long
# Public API #########################################################
-__import__ = _bootstrap.Import().__call__
+__import__ = _bootstrap._import
def import_module(name, package=None):
@@ -125,17 +125,15 @@ def import_module(name, package=None):
relative import to an absolute import.
"""
+ level = 0
if name.startswith('.'):
if not package:
raise TypeError("relative imports require the 'package' argument")
- level = 0
for character in name:
if character != '.':
break
level += 1
- name = Import._resolve_name(name[level:], package, level)
- __import__(name)
- return sys.modules[name]
+ return _bootstrap._gcd_import(name[level:], package, level)
# XXX This should go away once the public API is done.