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)
def _build_proxy_class(cls_name, builtins): proxy = raw_building.build_class(cls_name) proxy.parent = builtins return proxy
def _build_custom_builtin(self, obj_name): proxy = raw_building.build_class(obj_name) proxy.parent = self.builtins return proxy
def _build_proxy_class(cls_name, builtins): proxy = raw_building.build_class(cls_name)
def _build_custom_builtin(self, obj_name: str) -> ClassDef: proxy = raw_building.build_class(obj_name) proxy.parent = self.builtins return proxy
def _build_proxy_class(cls_name: str, builtins: nodes.Module) -> nodes.ClassDef: proxy = raw_building.build_class(cls_name) proxy.parent = builtins return proxy
def test_build_class(self) -> None: node = build_class("MyClass") self.assertEqual(node.name, "MyClass") self.assertEqual(node.doc, None)