Commits

Anonymous committed ffcd014

pycore: fixed importing a name from the same module

Comments (0)

Files changed (2)

rope/base/pynames.py

 
     def _get_imported_pyname(self):
         try:
-            return self.imported_module.get_object()[self.imported_name]
+            result = self.imported_module.get_object()[self.imported_name]
+            if result != self:
+                return result
         except exceptions.AttributeNotFoundError:
-            return UnboundName()
+            pass
+        return UnboundName()
 
+    _getting_object = False
     def get_object(self):
-        return self._get_imported_pyname().get_object()
+        if not self._getting_object:
+            try:
+                self._getting_object = True
+                return self._get_imported_pyname().get_object()
+            finally:
+                self._getting_object = False
+        return rope.base.pyobjects.get_unknown()
 
+    _getting_location = False
     def get_definition_location(self):
-        return self._get_imported_pyname().get_definition_location()
+        if not self._getting_location:
+            try:
+                self._getting_location = True
+                return self._get_imported_pyname().get_definition_location()
+            finally:
+                self._getting_location = False
+        return (None, None)
 
 
 class StarImport(object):

ropetest/pycoretest.py

         pymod1 = self.pycore.resource_to_pyobject(mod1)
         pymod1.get_attributes()
 
+    def test_not_reaching_maximum_recursions_when_importing_variables(self):
+        mod1 = testutils.create_module(self.project, 'mod1')
+        mod2 = testutils.create_module(self.project, 'mod2')
+        mod1.write('from mod2 import myvar\n')
+        mod2.write('from mod1 import myvar\n')
+        pymod1 = self.pycore.resource_to_pyobject(mod1)
+        pymod1['myvar'].get_object()
+
+    def test_not_reaching_maximum_recursions_when_importing_variables2(self):
+        mod1 = testutils.create_module(self.project, 'mod1')
+        mod1.write('from mod1 import myvar\n')
+        pymod1 = self.pycore.resource_to_pyobject(mod1)
+        pymod1['myvar'].get_object()
+
 
 class PyCoreInProjectsTest(unittest.TestCase):
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.