[Python-checkins] r55950 - sandbox/trunk/import_in_py/pseudocode.py
brett.cannon
python-checkins at python.org
Wed Jun 13 06:31:00 CEST 2007
Author: brett.cannon
Date: Wed Jun 13 06:30:56 2007
New Revision: 55950
Modified:
sandbox/trunk/import_in_py/pseudocode.py
Log:
Clean up comments.
Modified: sandbox/trunk/import_in_py/pseudocode.py
==============================================================================
--- sandbox/trunk/import_in_py/pseudocode.py (original)
+++ sandbox/trunk/import_in_py/pseudocode.py Wed Jun 13 06:30:56 2007
@@ -8,14 +8,17 @@
Caveats:
+ Classic relative import semantics are not covered.
+ Assume all code runs with the import lock held.
+ + Some structure (e.g., using importers for built-in and frozen
+ modules) is purely conceptual and not used in the C
+ implementation of import.
"""
path = globals.get('__path__')
# If a relative import, figure out absolute name of requested module.
if level != 0:
# Adjust relative import based on whether caller is a package and
- # the specified level.
- # Make sure import does not go beyond top-level.
+ # the specified level in the call.
+ # Also make sure import does not go beyond top-level.
name = resolve_name(name, globals['__name__'], path, level)
# Import each parent in the name, starting at the top.
# Assume each_parent iterates through each parent of the module request,
@@ -24,6 +27,7 @@
# import should be followed by 'continue' to let the next module be
# imported.
for parent in each_parent(name):
+ # If the module is already cached in sys.modules then move along.
if parent in sys.modules:
continue
# Search sys.meta_path.
@@ -89,19 +93,18 @@
# With the module now imported and store in sys.modules, figure out exactly
# what module to return based on fromlist and how the module name was
# specified.
- # If fromlist is empty, return the module top-most parent module based on
- # whether the import was relative or not.
if not fromlist:
+ # The fromlist is empty, so return the top-most parent module.
+ # Whether the import was relative or absolute must be considered.
if level:
return top_relative_name(name, level)
else:
return sys.modules[name.split('.', 1)[0]]
- # If fromlist is not empty, return the module as directly specified in the
- # import.
- # Must also handle possible imports of modules if the module imported was a
- # package and thus names in the fromlist are modules within the package and
- # not object within a module.
else:
+ # As fromlist is not empty, return the module specified by the import.
+ # Must also handle possible imports of modules if the module imported
+ # was a package and thus names in the fromlist are modules within the
+ # package and not object within a module.
module = sys.modules[name]
# If not a module, then can just return the module as the names
# specified in fromlist are supposed to be attributes on the module.
More information about the Python-checkins
mailing list