Attached Documents

generated-members-with-parent-patch (generated-members-with-parent.patch)

generated-members-with-parent-patch (generated-members-with-parent.patch)

Patch to 0.24.0 branch

download
diff -r 511d09d223c8 checkers/typecheck.py
--- a/checkers/typecheck.py	Mon Aug 08 10:21:28 2011 +0200
+++ b/checkers/typecheck.py	Thu Aug 25 19:39:48 2011 +0200
@@ -101,6 +101,13 @@
 missed by pylint inference system, and so shouldn\'t trigger E0201 when \
 accessed. Python regular expressions are accepted.'}
                 ),
+               ('generated-members-with-parent',
+                {'default' : (),
+                 'type': 'string',
+                 'metavar': 'ClassName.<members names/regexp>',
+                 'help': 'List of ClassName, members pairs which are set \
+dynamically and should not trigger E0201 when accessed'}
+               ),
         )
 
     def open(self):
@@ -133,6 +140,21 @@
             gen = shlex.shlex(self.config.generated_members)
             gen.whitespace += ','
             self.config.generated_members = tuple(tok.strip('"') for tok in gen)
+        if isinstance(self.config.generated_members_with_parent, str):
+            gen = shlex.shlex(self.config.generated_members_with_parent,
+                              posix=True)
+            gen.whitespace = ","
+            def reduce_fn(entries, entry):
+                # ignore invalid entries
+                if len(entry) == 2:
+                    if entry[0] in entries:
+                        entries[entry[0]].append(entry[1])
+                    else:
+                        entries.update({entry[0]: [entry[1]]})
+                return entries
+            self.config.generated_members_with_parent = reduce(reduce_fn,
+                                                (tok.split(".", 1)
+                                                for tok in gen), {})
         for pattern in self.config.generated_members:
             # attribute is marked as generated, stop here
             if re.match(pattern, node.attrname):
@@ -161,6 +183,12 @@
                 continue
             if ignoremim and name[-5:].lower() == 'mixin':
                 continue
+            if self.config.generated_members_with_parent and \
+               name in self.config.generated_members_with_parent:
+                for pattern in self.config.generated_members_with_parent[name]:
+                    # attribute is marked as generated for this class
+                    if re.match(pattern, node.attrname):
+                        return
             try:
                 if not [n for n in owner.getattr(node.attrname)
                         if not isinstance(n.statement(), astng.AugAssign)]: