Attached is my fix for the bug, along with a small test case. Cheers, -- Colin Morris Team Tahiti University of Toronto
On Mon, Mar 1, 2010 at 4:46 AM, Sylvain Thénault < sylvain.thena...@logilab.fr> wrote: > On 28 février 04:39, Colin Morris wrote: > > Hi, > > Hi Colin, > > > I've been looking at pylint ticket > > #9263<https://www.logilab.net/elo/ticket/9263>(no W0613 for __init__ > > (method does not use all of its arguments)). It looks > > like the problem occurs in the variables checker, at line 243, when the > > checker gives the method a pass if it's in PYMETHODS, a set of special > > Python functions. __init__ is in PYMETHODS, so it's never subject to > W0613 > > warnings. I think the check is still valuable for almost all other > methods > > in PYMETHODS, where the number of arguments is fixed. For example, it > seems > > reasonable that someone might want to define some object with infinite > > magnitude, and override its __ge__ method to just return True -- but > because > > __gt__ must take two arguments, including self, having an unused argument > is > > unavoidable. > > > > As far as I can tell, the only two methods in PYMETHODS where it's still > > desirable to check for unused arguments would be __init__ and __new__. > > PYMETHODS is used by other checkers, so changing it doesn't seem like a > > possibility. My proposed solution would be to just add another condition > to > > 243 so that it reads something like "if node.name in PYMETHODS and > > node.namenot in ('__init__', '__new__'):". Does this seem like a > > reasonable fix? > > yup > > -- > Sylvain Thénault LOGILAB, Paris (France) > Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations > Développement logiciel sur mesure: http://www.logilab.fr/services > CubicWeb, the semantic web framework: http://www.cubicweb.org > >
diff -r 1e7951104f94 checkers/variables.py --- a/checkers/variables.py Tue Mar 02 01:27:44 2010 +0100 +++ b/checkers/variables.py Wed Mar 03 02:52:35 2010 -0500 @@ -240,7 +240,7 @@ overridden = overridden_method(klass, node.name) if overridden is not None and name in overridden.argnames(): continue - if node.name in PYMETHODS: + if node.name in PYMETHODS and node.name not in ('__init__', '__new__'): continue # don't check callback arguments XXX should be configurable if node.name.startswith('cb_') or node.name.endswith('_cb'): diff -r 1e7951104f94 test/input/func_w0613.py --- a/test/input/func_w0613.py Tue Mar 02 01:27:44 2010 +0100 +++ b/test/input/func_w0613.py Wed Mar 03 02:52:35 2010 -0500 @@ -33,3 +33,11 @@ return req.vreg.etype_class(etype)(req, rset, row, col) # pylint: disable-msg = W0201 rset.get_entity = inner + +class BBBB: + """dummy class""" + + def __init__(self, arg): + """Constructor with an extra parameter. Should raise a warning""" + self.spam = 1 + diff -r 1e7951104f94 test/messages/func_w0613.txt --- a/test/messages/func_w0613.txt Tue Mar 02 01:27:44 2010 +0100 +++ b/test/messages/func_w0613.txt Wed Mar 03 02:52:35 2010 -0500 @@ -2,3 +2,4 @@ W: 14:AAAA.method: Unused argument 'arg' W: 21:AAAA.selected: Unused argument 'args' W: 21:AAAA.selected: Unused argument 'kwargs' +W: 40:BBBB.__init__: Unused argument 'arg'
_______________________________________________ Python-Projects mailing list Python-Projects@lists.logilab.org http://lists.logilab.org/mailman/listinfo/python-projects