Virgil Dupras avatar Virgil Dupras committed 6b8bfc9

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

Taken from commit by Ronny Pfannschmidt at https://bitbucket.org/birkenfeld/pyflakes-ast/changeset/fa51a3be99e1

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)
 
             raise RuntimeError("Got impossible expression context: %r" % (node.ctx,))
 
     def FUNCTIONDEF(self, node):
+        is_property = False
         for deco in node.decorator_list:
             self.handleNode(deco, node)
-        self.addBinding(node.lineno, FunctionDefinition(node.name, 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')
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.