Index: codegen/codegen.py
===================================================================
--- codegen/codegen.py	(revision 964)
+++ codegen/codegen.py	(working copy)
@@ -1374,9 +1374,10 @@
 
     def write_imports(self):
         self.fp.write('/* ---------- types from other modules ---------- */\n')
-        for module, pyname, cname in self.overrides.get_imports():
-            self.fp.write('static PyTypeObject *_%s;\n' % cname)
-            self.fp.write('#define %s (*_%s)\n' % (cname, cname))
+        for module, pyname, cname, importing_for in self.overrides.get_imports():
+            if importing_for is None or is_registered_object(importing_for):
+                self.fp.write('static PyTypeObject *_%s;\n' % cname)
+                self.fp.write('#define %s (*_%s)\n' % (cname, cname))
         self.fp.write('\n\n')
 
     def write_type_declarations(self):
@@ -1485,8 +1486,9 @@
             return
 
         bymod = {}
-        for module, pyname, cname in imports:
-            bymod.setdefault(module, []).append((pyname, cname))
+        for module, pyname, cname, importing_for in imports:
+            if importing_for is None or is_registered_object(importing_for):
+                bymod.setdefault(module, []).append((pyname, cname))
         self.fp.write('    PyObject *module;\n\n')
         for module in bymod:
             self.fp.write(
@@ -1625,6 +1627,9 @@
 
 _objects = {}
 
+def is_registered_object(c_name):
+    return c_name in _objects
+
 def get_object_by_name(c_name):
     global _objects
     return _objects[c_name]
Index: codegen/override.py
===================================================================
--- codegen/override.py	(revision 964)
+++ codegen/override.py	(working copy)
@@ -19,7 +19,7 @@
             c_name += c
     return c_name[1:] + '_'  + method
 
-import_pat = re.compile(r'\s*import\s+(\S+)\.([^\s.]+)\s+as\s+(\S+)')
+import_pat = re.compile(r'\s*import\s+(\S+)\.([^\s.]+)\s+as\s+(\S+)(\s+for\s+(\S+))?')
 
 class Overrides:
     def __init__(self, filename=None):
@@ -166,7 +166,8 @@
             for line in string.split(buffer, '\n'):
                 match = import_pat.match(line)
                 if match:
-                    self.imports.append(match.groups())
+                    module, pyname, cname, conditional, importing_for = match.groups()
+                    self.imports.append((module, pyname, cname, importing_for or None))
         elif command == 'define':
             "define funcname [kwargs|noargs|onearg] [classmethod|staticmethod]"
             "define Class.method [kwargs|noargs|onearg] [classmethod|staticmethod]"
