示例#1
0
 def visit_DictComp(self, node: ast.DictComp) -> ast.DictComp:
     """
     A dict comprehension.
     """
     self.generic_visit(node)
     node.key = self.visit(node.key)
     node.value = self.visit(node.value)
     return node
示例#2
0
def _visit_dict_comp(self: 'ASTTagger', node: ast.DictComp):
    new = self.symtable.enter_new()
    new.entered.add('.0')
    new_tagger = ASTTagger(new)
    node.key = new_tagger.visit(node.key)
    node.value = new_tagger.visit(node.value)

    head, *tail = node.generators
    head.iter = self.visit(head.iter)
    head.target = new_tagger.visit(head.target)
    if head.ifs:
        head.ifs = [new_tagger.visit(each) for each in head.ifs]

    if any(each.is_async for each in node.generators):
        new.cts.add(ContextType.Coroutine)
    node.generators = [head, *[new_tagger.visit(each) for each in tail]]

    return Tag(node, new)
示例#3
0
文件: logging.py 项目: Auzzy/pystick
 def init(vars):
     node = Name(id=Log.log_dict, ctx=Store())
     var_strs = [Str(s=var.name) for var in vars]
     void = Call(func=Name(id='Void', ctx=Load()))
     return [
         Assign(targets=[node],
                value=DictComp(key=Name(id='__key', ctx=Load()),
                               value=Log.__fromkeys(var_strs, void),
                               generators=[
                                   comprehension(target=Name(id='__key',
                                                             ctx=Store()),
                                                 iter=Log.__fromkeys(
                                                     Log.sections))
                               ]))
     ]