A few little enhancements to the py3flakes checker and a Python 3.3 extension for it. 5_2_x

Wed, 03 Oct 2012 13:20:57 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 03 Oct 2012 13:20:57 +0200
branch
5_2_x
changeset 2091
cf95a549ec91
parent 2090
a74544498a96
child 2092
987aa24ec704

A few little enhancements to the py3flakes checker and a Python 3.3 extension for it.
(grafted from d23ab571d2b9c3cf3cdd22c2d5cbd6d6e3dbef6e)

Utilities/py3flakes/checker.py file | annotate | diff | comparison | revisions
--- a/Utilities/py3flakes/checker.py	Wed Oct 03 12:18:51 2012 +0200
+++ b/Utilities/py3flakes/checker.py	Wed Oct 03 13:20:57 2012 +0200
@@ -74,7 +74,7 @@
     """
     Represents a function definition.
     """
-    pass
+    is_property = False
 
 
 class ExportBinding(Binding):
@@ -302,8 +302,8 @@
     ISNOT = IN = NOTIN = ignore
 
     # "stmt" type nodes
-    RETURN = DELETE = PRINT = WHILE = IF = WITH = RAISE = TRYEXCEPT = \
-        TRYFINALLY = ASSERT = EXEC = EXPR = handleChildren
+    RETURN = DELETE = PRINT = WHILE = IF = WITH = WITHITEM = RAISE = \
+    TRYEXCEPT = TRYFINALLY = ASSERT = EXEC = EXPR = handleChildren
     
     # "expr" type nodes
     BOOLOP = BINOP = UNARYOP = IFEXP = DICT = SET = YIELD = COMPARE = \
@@ -326,7 +326,9 @@
             reported (boolean)
         '''
         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)
 
@@ -487,10 +489,17 @@
                 "Got impossible expression context: {0:r}".format(node.ctx,))
 
     def FUNCTIONDEF(self, node):
+        is_property = False
         if hasattr(node, "decorator_list"):
             for decorator in node.decorator_list:
                 self.handleNode(decorator, node)
-        self.addBinding(node.lineno, FunctionDefinition(node.name, node))
+                if getattr(decorator, 'id', None) == 'property':
+                    is_property = True
+                if getattr(decorator, '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):

eric ide

mercurial