示例#1
0
def build_binary_op(assnode):
    left = assnode.expr.left.as_string()
    right = assnode.expr.right.as_string()
    statement = "%s" % (left + " % " + right)
    dic = dict((key, key) for key in assnode.frame().locals)
    try:
        new_statement = eval(statement, {}, dic)
    except Exception:
        return
    parsed = parseExecLine(new_statement, mode="single")
    if parsed.errors: return
    if parsed.importfrom:
        name = parsed.alias or parsed.importwhat
        newClass = raw_building.build_class(name)
        assnode.root().add_local_node(newClass, name)
    elif parsed.targets:
        value = parsed.values[0]
        new_value = ""
        if isinstance(value, ast.Name):
            new_value = value.id
        raw_building.attach_const_node(assnode.scope(), parsed.targets[0], new_value)
 def test_build_class(self):
     node = build_class('MyClass')
     self.assertEqual(node.name, 'MyClass')
     self.assertEqual(node.doc, None)
示例#3
0
 def test_build_class(self):
     node = build_class('MyClass')
     self.assertEqual(node.name, 'MyClass')
     self.assertEqual(node.doc, None)
示例#4
0
def _build_proxy_class(cls_name, builtins):
    proxy = raw_building.build_class(cls_name)
    proxy.parent = builtins
    return proxy
示例#5
0
def _build_proxy_class(cls_name, builtins):
    proxy = raw_building.build_class(cls_name)
    proxy.parent = builtins
    return proxy
示例#6
0
 def _build_custom_builtin(self, obj_name):
     proxy = raw_building.build_class(obj_name)
     proxy.parent = self.builtins
     return proxy
示例#7
0
文件: helpers.py 项目: prihit/we-care
def _build_proxy_class(cls_name, builtins):
    proxy = raw_building.build_class(cls_name)
示例#8
0
 def _build_custom_builtin(self, obj_name: str) -> ClassDef:
     proxy = raw_building.build_class(obj_name)
     proxy.parent = self.builtins
     return proxy
示例#9
0
def _build_proxy_class(cls_name: str,
                       builtins: nodes.Module) -> nodes.ClassDef:
    proxy = raw_building.build_class(cls_name)
    proxy.parent = builtins
    return proxy
示例#10
0
 def test_build_class(self) -> None:
     node = build_class("MyClass")
     self.assertEqual(node.name, "MyClass")
     self.assertEqual(node.doc, None)