On 17 septembre 19:56, Huurne, Maarten ter wrote:
> Hi,

Hi Maarten, 

> When inheriting from "dict" and overriding methods, W0613 is issued on some 
> methods:
> 
> ===
> class DictArgInstance(dict):
> 
>         def __delitem__(self, key):
>                 raise TypeError('attempt to modify read-only dictionary')
> 
>         def __setitem__(self, key, value):
>                 raise TypeError('attempt to modify read-only dictionary')
> 
>         def clear(self):
>                 raise TypeError('attempt to modify read-only dictionary')
> 
>         def pop(self, key, default):
>                 raise TypeError('attempt to modify read-only dictionary')
> 
>         def popitem(self):
>                 raise TypeError('attempt to modify read-only dictionary')
> 
>         def setdefault(self, key, default):
>                 raise TypeError('attempt to modify read-only dictionary')
> 
>         def update(self, d, **kvargs):
>                 raise TypeError('attempt to modify read-only dictionary')
> ===
> W0613: 12:DictArgInstance.pop: Unused argument 'default'
> W0613: 12:DictArgInstance.pop: Unused argument 'key'
> W0613: 18:DictArgInstance.setdefault: Unused argument 'default'
> W0613: 18:DictArgInstance.setdefault: Unused argument 'key'
> W0613: 21:DictArgInstance.update: Unused argument 'kvargs'
> W0613: 21:DictArgInstance.update: Unused argument 'd'
> ===
> 
> Apparently "__delitem__" and "__setitem__" are recognized as super class 
> methods and W0613 is suppressed there. But that is not the case for "pop", 
> "setdefault" and "update".
> 
> As "dict" is implemented in native code, the way to get information about it 
> is through introspection. I have been unable to find "__code__" attributes on 
> the problematic methods though. Does anyone know how to get information about 
> argument count and names for methods implemented as <type 
> 'method_descriptor'>?
> 
> An alternative to introspection would be to have hardcoded information about 
> built-in classes, but that could get outdated when new optional arguments are 
> added in new Python versions. Also it would only solve the problem for 
> classes from Python itself.
> 
> The fact that a method overrides another, as opposed to defining a new 
> method, is easy to check. Therefore, an alternative would be to suppress 
> W0613 when a method is overridden, even if the arguments of the method in the 
> super class cannot be determined.

right. Filed: http://www.logilab.org/ticket/18778

Thanks,
-- 
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

_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to