pylint #18778 W0613 false positive on overridden dictionary methods [open]
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') Result 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. Bye, Maarten | |
priority | normal |
---|---|
type | bug |
done in | <not specified> |
load | 0.200 |
load left | 0.200 |
closed by | <not specified> |