Commits

Ronny Pfannschmidt committed fa51a3b

allow function redefinition for modern property construction via property.detter/deleter

Comments (0)

Files changed (2)

pyflakes/checker.py

 
 
 class FunctionDefinition(Binding):
-    pass
+    is_property = False
 
 
 
           reported.
         '''
         if (isinstance(self.scope.get(value.name), FunctionDefinition)
-                    and isinstance(value, FunctionDefinition)):
+                    and isinstance(value, FunctionDefinition)
+                    and not self.scope.get(value.name).is_property
+                    and not value.is_property):
             self.report(messages.RedefinedFunction,
                         lineno, value.name, self.scope[value.name].source.lineno)
 
 
     def FUNCTIONDEF(self, node):
         # the decorators attribute is called decorator_list as of Python 2.6
+        is_property = False
         if hasattr(node, 'decorators'):
-            for deco in node.decorators:
-                self.handleNode(deco, node)
+            decorators = node.decorators
         else:
-            for deco in node.decorator_list:
-                self.handleNode(deco, node)
-        self.addBinding(node.lineno, FunctionDefinition(node.name, node))
+            decorators = node.decorator_list
+
+        for deco in decorators:
+            self.handleNode(deco, node)
+            if getattr(deco, 'id', None) == 'property':
+                is_property = True
+            if getattr(deco, 'attr', None) in ('setter', 'deleter'):
+                is_property = True
+
+        funcdef = FunctionDefinition(node.name, node)
+        funcdef.is_property = is_property
+        self.addBinding(node.lineno, funcdef)
         self.LAMBDA(node)
 
     def LAMBDA(self, node):

pyflakes/test/test_other.py

             a = classmethod(a)
         ''')
 
+    def test_modern_property(self):
+        self.flakes("""
+        class A:
+            @property
+            def t(self):
+                pass
+            @t.setter
+            def t(self, value):
+                pass
+            @t.deleter
+            def t(self):
+                pass
+        """)
+
     def test_unaryPlus(self):
         '''Don't die on unary +'''
         self.flakes('+1')