pylintext.py
changeset 8061 88ca47ceb9f2
parent 7941 018b5deca73e
child 8190 2a3c1b787688
child 8198 ce9c6ae03c2d
equal deleted inserted replaced
8060:8acfd23578a8 8061:88ca47ceb9f2
     1 """https://pastebin.logilab.fr/show/860/"""
     1 """https://pastebin.logilab.fr/show/860/"""
     2 
     2 
     3 from logilab.astng import MANAGER, nodes, scoped_nodes
     3 from logilab.astng import MANAGER, nodes, scoped_nodes
       
     4 from logilab.astng.builder import ASTNGBuilder
     4 
     5 
     5 def turn_function_to_class(node):
     6 def turn_function_to_class(node):
     6     """turn a Function node into a Class node (in-place)"""
     7     """turn a Function node into a Class node (in-place)"""
     7     node.__class__ = scoped_nodes.Class
     8     node.__class__ = scoped_nodes.Class
     8     node.bases = ()
     9     node.bases = ()
    31     # magic in there
    32     # magic in there
    32     if module.name == 'yams.buildobjs':
    33     if module.name == 'yams.buildobjs':
    33         from yams import BASE_TYPES
    34         from yams import BASE_TYPES
    34         for etype in BASE_TYPES:
    35         for etype in BASE_TYPES:
    35             module.locals[etype] = [scoped_nodes.Class(etype, None)]
    36             module.locals[etype] = [scoped_nodes.Class(etype, None)]
    36 
    37     # add data() to uiprops module
    37 MANAGER.register_transformer(cubicweb_transform)
    38     if module.name.endswith('.uiprops'):
       
    39         fake = ASTNGBuilder(MANAGER).string_build('''
       
    40 def data(string):
       
    41   return u''
       
    42 ''')
       
    43         module.locals['data'] = fake.locals['data']
    38 
    44 
    39 def register(linter):
    45 def register(linter):
    40     """called when loaded by pylint --load-plugins, nothing to do here"""
    46     """called when loaded by pylint --load-plugins, nothing to do here"""
       
    47     MANAGER.register_transformer(cubicweb_transform)
    41 
    48