[Python-checkins] r55749 - sandbox/trunk/import_in_py/pseudocode.py
brett.cannon
python-checkins at python.org
Sun Jun 3 21:50:54 CEST 2007
Author: brett.cannon
Date: Sun Jun 3 21:50:53 2007
New Revision: 55749
Added:
sandbox/trunk/import_in_py/pseudocode.py (contents, props changed)
Log:
Begin a file containing the pseudocode of how imports work.
Added: sandbox/trunk/import_in_py/pseudocode.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/import_in_py/pseudocode.py Sun Jun 3 21:50:53 2007
@@ -0,0 +1,21 @@
+"""Pseudocode to explain how importing works.
+
+Caveats:
+ + Classic relative import semantics are not currently covered.
+ + Assume all code runs with the import lock held.
+
+"""
+if level != 0: # Relative import.
+ name = resolve_name(name, level) # XXX
+# Import each parent in the name, starting at root.
+# Skipping over details of constructing each parent name and setting the proper
+# attribute on the parent for newly imported modules.
+for parent in name:
+ if parent in sys.modules:
+ continue
+ for meta_importer in sys.meta_path:
+ check_meta_path(parent, meta_importer) # XXX
+ for path_entry in sys.path:
+ check_path(parent, path_entry) # XXX
+ # XXX error: not found
+return module_to_return(path, fromlist) # XXX
More information about the Python-checkins
mailing list