Commits

Anonymous committed a00c212

Handling circular from imports

Comments (0)

Files changed (5)

 ===========
 
 
+- Handle circular from-imports : July 14, 2006
+
+
 - Completeing ``AClass(param).a_`` : July 11, 2006
 
 
 * We know the type of list and keyword args
 
 
-* Handle circular from-imports
-
-
 * Introduce factory method
 
 

docs/workingon.txt

 Out of project modules @ 28h
 ============================
 
-- Using absolute paths
-- Adding OutOfProjectTest to suite()
-- Test get_child, has_child
-- Out of project resources should be reference objects
 * zip imports
 
 Out Of Project Resources
 
     def get_attributes(self):
         if self.attributes is None:
-            self.attributes = self._get_attributes_from_ast()
+            self.attributes = {}
+            self._update_attributes_from_ast(self.attributes)
         return self.attributes
 
     def get_scope(self):
             current_object = current_object.parent
         return current_object
 
-    def _get_attributes_from_ast(self):
+    def _update_attributes_from_ast(self, attributes):
         pass
 
     def _get_ast(self):
         self.parameters = self.ast_node.argnames
         self.decorators = self.ast_node.decorators
 
-    def _get_attributes_from_ast(self):
-        return {}
+    def _update_attributes_from_ast(self, attributes):
+        pass
     
     def _create_scope(self):
         return FunctionScope(self.pycore, self)
                                       pycore, ast_node, parent)
         self.parent = parent
 
-    def _get_attributes_from_ast(self):
-        result = {}
+    def _update_attributes_from_ast(self, attributes):
         for base in self._get_bases():
-            result.update(base.get_attributes())
+            attributes.update(base.get_attributes())
         new_visitor = _ClassVisitor(self.pycore, self)
         for n in self.ast_node.getChildNodes():
             compiler.walk(n, new_visitor)
-        result.update(new_visitor.names)
-        return result
+        attributes.update(new_visitor.names)
 
     def _get_bases(self):
         result = []
         self.resource = resource
         self.is_package = False
 
-    def _get_attributes_from_ast(self):
+    def _update_attributes_from_ast(self, attributes):
         visitor = _GlobalVisitor(self.pycore, self)
         compiler.walk(self.ast_node, visitor)
-        return visitor.names
+        attributes.update(visitor.names)
 
     def _create_scope(self):
         return GlobalScope(self.pycore, self)

ropetest/pycoretest.py

         mod2.write('import mod1\n')
         module1 = self.pycore.get_module('mod1')
 
+    def test_circular_imports2(self):
+        mod1 = self.pycore.create_module(self.project.get_root_folder(), 'mod1')
+        mod2 = self.pycore.create_module(self.project.get_root_folder(), 'mod2')
+        mod1.write('from mod2 import Sample2\nclass Sample1(object):\n    pass\n')
+        mod2.write('from mod1 import Sample1\nclass Sample2(object):\n    pass\n')
+        module1 = self.pycore.get_module('mod1').get_attributes()
+
     def test_multi_dot_imports(self):
         pkg = self.pycore.create_package(self.project.get_root_folder(), 'pkg')
         pkg_mod = self.pycore.create_module(pkg, 'mod')