equal
deleted
inserted
replaced
1 """Pylint plugin for cubicweb""" |
1 """Pylint plugin for cubicweb""" |
2 |
2 |
3 from astroid import MANAGER, InferenceError, nodes, scoped_nodes, ClassDef, FunctionDef |
3 from astroid import MANAGER, InferenceError, nodes, scoped_nodes, ClassDef, FunctionDef |
4 from astroid.builder import AstroidBuilder |
4 from astroid.builder import AstroidBuilder |
|
5 from pylint.checkers.utils import unimplemented_abstract_methods, class_is_abstract |
5 |
6 |
6 |
7 |
7 def turn_function_to_class(node): |
8 def turn_function_to_class(node): |
8 """turn a Function node into a Class node (in-place)""" |
9 """turn a Function node into a Class node (in-place)""" |
9 node.__class__ = ClassDef |
10 node.__class__ = ClassDef |
45 return u'' |
46 return u'' |
46 ''') |
47 ''') |
47 module.locals['data'] = fake.locals['data'] |
48 module.locals['data'] = fake.locals['data'] |
48 |
49 |
49 |
50 |
|
51 def cubicweb_abstractmethods_transform(classdef): |
|
52 if class_is_abstract(classdef): |
|
53 return |
|
54 |
|
55 def is_abstract(method): |
|
56 return method.is_abstract(pass_is_abstract=False) |
|
57 |
|
58 methods = sorted( |
|
59 unimplemented_abstract_methods(classdef, is_abstract).items(), |
|
60 key=lambda item: item[0], |
|
61 ) |
|
62 |
|
63 def dummy_method(): |
|
64 """""" |
|
65 for name, method in methods: |
|
66 owner = method.parent.frame() |
|
67 if owner is classdef: |
|
68 continue |
|
69 if name not in classdef.locals: |
|
70 if name in ('entity_call', 'render_body'): |
|
71 classdef.set_local(name, dummy_method) |
|
72 |
|
73 |
50 def register(linter): |
74 def register(linter): |
51 """called when loaded by pylint --load-plugins, nothing to do here""" |
75 """called when loaded by pylint --load-plugins, nothing to do here""" |
52 MANAGER.register_transform(nodes.Module, cubicweb_transform) |
76 MANAGER.register_transform(nodes.Module, cubicweb_transform) |
|
77 MANAGER.register_transform(nodes.ClassDef, cubicweb_abstractmethods_transform) |