Anonymous avatar Anonymous committed 120122f

pyobjectsdef: passing the correct object to property decorateds

Comments (0)

Files changed (2)

rope/base/pyobjectsdef.py

         pyfunction = PyFunction(self.pycore, node, self.owner_object)
         for decorator in pyfunction.decorators:
             if isinstance(decorator, ast.Name) and decorator.id == 'property':
-                property_type = rope.base.builtins.Property(pyfunction)
-                arg = pynames.UnboundName(PyObject(None))
-                def _eval():
-                    return property_type.get_property_object(
-                        rope.base.evaluate.ObjectArguments([arg]))
-                self.names[node.name] = pynames.EvaluatedName(_eval)
-                break
+                if isinstance(self, _ClassVisitor):
+                    property_type = rope.base.builtins.Property(pyfunction)
+                    arg = pynames.UnboundName(PyObject(self.owner_object))
+                    def _eval(property_type=property_type, arg=arg):
+                        return property_type.get_property_object(
+                            rope.base.evaluate.ObjectArguments([arg]))
+                    self.names[node.name] = pynames.EvaluatedName(_eval)
+                    break
         else:
             self.names[node.name] = pynames.DefinedName(pyfunction)
         self.defineds.append(pyfunction)

ropetest/objectinfertest.py

         a = mod['A'].get_object()
         self.assertEquals(a, var.get_type())
 
+    def test_using_property_as_decorators_and_passing_parameter(self):
+        code = 'class B(object):\n' \
+               '    @property\n    def f(self):\n        return self\n' \
+               'b = B()\nvar = b.f\n'
+        mod = self.pycore.get_string_module(code)
+        var = mod['var'].get_object()
+        a = mod['B'].get_object()
+        self.assertEquals(a, var.get_type())
+
 
 def suite():
     result = unittest.TestSuite()
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.