As the subject says, this line gives a warning but should not:
super(self, Foo)._bar()
tmarek observed to me that it would be nice to do some type inference on
checking for protected methods, and I agree it would be nice, because then
this would work too:
a=self;a._protected_method()
However, calling a protected method on a super object is a pretty common
case, so I think this is a step forward as it is.
--
Martin
--- pylint/checkers/classes.py 2012-10-24 03:43:20.000000000 +1100
+++ pylint/checkers/classes.py 2012-12-28 14:49:13.000000000 +1100
@@ -386,10 +386,15 @@
self.add_message('W0212', node=node, args=attrname)
return
+ # If the expression begins with a call to super, that's ok.
+ if isinstance(node.expr, astng.CallFunc) and \
+ isinstance(node.expr.func, astng.Name) and \
+ node.expr.func.name == 'super':
+ return
+
# We are in a class, one remaining valid cases, Klass._attr
inside
# Klass
if not (callee == klass.name or callee in klass.basenames):
-
self.add_message('W0212', node=node, args=attrname)
def visit_name(self, node):
--- /dev/null 2013-01-07 10:44:38.067492040 +1100
+++ pylint/test/input/func_noerror_super_protected.py 2012-12-28
14:48:25.000000000 +1100
@@ -0,0 +1,22 @@
+"""Accessing a protected method through super() is ok."""
+
+# pylint: disable=missing-docstring,too-few-public-methods
+
+__revision__ = None
+
+class Alpha(object):
+
+ _secret = 2
+
+ def test(self):
+ print "test %s" % self
+
+
+class Beta(Alpha):
+
+ def test(self):
+ print super(Beta, self)._secret
+ super(Beta, self).test()
+
+
+Beta().test()
_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects