diff options
author | Martin Pool <mbp@google.com> | 2013-01-08 18:35:22 +0100 |
---|---|---|
committer | Martin Pool <mbp@google.com> | 2013-01-08 18:35:22 +0100 |
commit | d39bd9e81f9fc6930f81f5bfda8ab83879fd8bdd (patch) | |
tree | 91083d983813ce572b4f9ec8ac18afb0da44e750 | |
parent | 6441eac02dc68b847a5b0af2c7e3626cbcffaa27 (diff) | |
download | pylint-d39bd9e81f9fc6930f81f5bfda8ab83879fd8bdd.tar.gz |
erroneous W0212 (access to protected member) on super call. Closes #115580
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | checkers/classes.py | 7 | ||||
-rw-r--r-- | test/input/func_noerror_super_protected.py | 22 |
3 files changed, 32 insertions, 2 deletions
@@ -2,7 +2,10 @@ ChangeLog for PyLint ==================== -- - * #110853: Fix a crash when an __init__ method in a base class has been + * #115580: fix erroneous W0212 (access to protected member) on super call + (patch by Martin Pool) + + * #110853: fix a crash when an __init__ method in a base class has been created by assignment rather than direct function definition. (patch by Torsten Marek) diff --git a/checkers/classes.py b/checkers/classes.py index 1259d18..f2c2913 100644 --- a/checkers/classes.py +++ b/checkers/classes.py @@ -386,10 +386,15 @@ a metaclass class method.'} 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): diff --git a/test/input/func_noerror_super_protected.py b/test/input/func_noerror_super_protected.py new file mode 100644 index 0000000..5e78eea --- /dev/null +++ b/test/input/func_noerror_super_protected.py @@ -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() |