Exemplo n.º 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)
Exemplo n.º 3
0
 def test_build_class(self):
     node = build_class('MyClass')
     self.assertEqual(node.name, 'MyClass')
     self.assertEqual(node.doc, None)
Exemplo n.º 4
0
def _build_proxy_class(cls_name, builtins):
    proxy = raw_building.build_class(cls_name)
    proxy.parent = builtins
    return proxy
Exemplo n.º 5
0
def _build_proxy_class(cls_name, builtins):
    proxy = raw_building.build_class(cls_name)
    proxy.parent = builtins
    return proxy
Exemplo n.º 6
0
 def _build_custom_builtin(self, obj_name):
     proxy = raw_building.build_class(obj_name)
     proxy.parent = self.builtins
     return proxy
Exemplo n.º 7
0
def _build_proxy_class(cls_name, builtins):
    proxy = raw_building.build_class(cls_name)
Exemplo n.º 8
0
 def _build_custom_builtin(self, obj_name: str) -> ClassDef:
     proxy = raw_building.build_class(obj_name)
     proxy.parent = self.builtins
     return proxy
Exemplo n.º 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
Exemplo n.º 10
0
 def test_build_class(self) -> None:
     node = build_class("MyClass")
     self.assertEqual(node.name, "MyClass")
     self.assertEqual(node.doc, None)