[pylint] remove abstract-method warning
authorLaura Médioni <laura.medioni@logilab.fr>
Tue, 19 Jan 2016 14:07:59 +0100
changeset 11218 3fea2f3b25c1
parent 11217 1f686f55ef3d
child 11219 0796b6191cea
[pylint] remove abstract-method warning This kind of message is targeted: "Method 'entity_call' is abstract in class 'EntityView' but is not overridden (abstract-method)" For now, only "entity_call" and "render_body" are dealt with, the list can be extended.
cubicweb/pylintext.py
--- a/cubicweb/pylintext.py	Tue Jan 19 11:43:52 2016 +0100
+++ b/cubicweb/pylintext.py	Tue Jan 19 14:07:59 2016 +0100
@@ -2,6 +2,7 @@
 
 from astroid import MANAGER, InferenceError, nodes, scoped_nodes, ClassDef, FunctionDef
 from astroid.builder import AstroidBuilder
+from pylint.checkers.utils import unimplemented_abstract_methods, class_is_abstract
 
 
 def turn_function_to_class(node):
@@ -47,6 +48,30 @@
         module.locals['data'] = fake.locals['data']
 
 
+def cubicweb_abstractmethods_transform(classdef):
+    if class_is_abstract(classdef):
+        return
+
+    def is_abstract(method):
+        return method.is_abstract(pass_is_abstract=False)
+
+    methods = sorted(
+        unimplemented_abstract_methods(classdef, is_abstract).items(),
+        key=lambda item: item[0],
+    )
+
+    def dummy_method():
+        """"""
+    for name, method in methods:
+        owner = method.parent.frame()
+        if owner is classdef:
+            continue
+        if name not in classdef.locals:
+            if name in ('entity_call', 'render_body'):
+                classdef.set_local(name, dummy_method)
+
+
 def register(linter):
     """called when loaded by pylint --load-plugins, nothing to do here"""
     MANAGER.register_transform(nodes.Module, cubicweb_transform)
+    MANAGER.register_transform(nodes.ClassDef, cubicweb_abstractmethods_transform)