I'm using the "ignored-classes" configuration option to disable the E1101
error for a class which has some generated members.  Unfortunately, this
seems to have no effect on subclasses of the ignored class.

I think it makes sense for any subclass of an ignored class to
automatically be ignored, as otherwise attempting to access one of the base
class generated members via an instance of a subclass will give an E1101
error.

The following patch implements this behaviour.

I suspect my patch is incredibly inefficient, as it will infer the types of
every base class on every attribute access.  Is there a better way to do
this?  Should I create a cache that maps a class to whether or not that
class is ignored?

Thanks,
James.


--- checkers/typecheck.py       2012-02-03 09:21:33.922873777 -0800
+++ checkers/typecheck.py       2012-02-14 08:38:30.718588652 -0800
@@ -60,6 +60,17 @@
               argument and one from a keyword argument.'),
     }

+def is_ignored_class(cls, ignored_classes):
+   name = getattr(cls, 'name', 'None')
+   if name in ignored_classes:
+      return True
+   if hasattr(cls, 'bases'):
+      for base in cls.bases:
+         for c in base.infer():
+            if is_ignored_class(c, ignored_classes):
+               return True
+   return False
+
 class TypeChecker(BaseChecker):
     """try to find bugs in the code using type inference
     """
@@ -156,8 +167,7 @@
             # XXX "super" / metaclass call
             if is_super(owner) or getattr(owner, 'type', None) ==
'metaclass':
                 continue
-            name = getattr(owner, 'name', 'None')
-            if name in self.config.ignored_classes:
+            if is_ignored_class(owner, self.config.ignored_classes):
                 continue
             if ignoremim and name[-5:].lower() == 'mixin':
                 continue
@@ -170,6 +170,7 @@
                 if owner.name == 'Values' and \
                        owner.root().name in ('optik', 'optparse'):
                     continue
+                name = getattr(owner, 'name', 'None')
                 missingattr.add((owner, name))
                 continue
             # stop on the first found
_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to