[pylint] enhance plugin: define 'data' function in uiprops module
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 07 Nov 2011 10:56:39 +0100
changeset 8061 88ca47ceb9f2
parent 8060 8acfd23578a8
child 8064 6d8eb873256d
[pylint] enhance plugin: define 'data' function in uiprops module
pylintext.py
--- a/pylintext.py	Mon Nov 07 10:55:15 2011 +0100
+++ b/pylintext.py	Mon Nov 07 10:56:39 2011 +0100
@@ -1,6 +1,7 @@
 """https://pastebin.logilab.fr/show/860/"""
 
 from logilab.astng import MANAGER, nodes, scoped_nodes
+from logilab.astng.builder import ASTNGBuilder
 
 def turn_function_to_class(node):
     """turn a Function node into a Class node (in-place)"""
@@ -33,9 +34,15 @@
         from yams import BASE_TYPES
         for etype in BASE_TYPES:
             module.locals[etype] = [scoped_nodes.Class(etype, None)]
-
-MANAGER.register_transformer(cubicweb_transform)
+    # add data() to uiprops module
+    if module.name.endswith('.uiprops'):
+        fake = ASTNGBuilder(MANAGER).string_build('''
+def data(string):
+  return u''
+''')
+        module.locals['data'] = fake.locals['data']
 
 def register(linter):
     """called when loaded by pylint --load-plugins, nothing to do here"""
+    MANAGER.register_transformer(cubicweb_transform)