(self, no_modify = False)
| 229 | return node |
| 230 | |
| 231 | def run(self, no_modify = False): |
| 232 | try: |
| 233 | remover = CommentRemover(self.code) |
| 234 | new_code = remover.run().strip() |
| 235 | if len(new_code) == 0: |
| 236 | return -1, False |
| 237 | self.visitor = CodeVisitor(new_code) |
| 238 | self.visitor.run() |
| 239 | self.root = ast.parse(self.code) |
| 240 | if self.visitor.all_func_in_class: |
| 241 | if no_modify: |
| 242 | return ast.unparse(self.root), False |
| 243 | self.classname = self.visitor.classes[-1] |
| 244 | self.funcname = None |
| 245 | for func_name in self.visitor.func_names: |
| 246 | if func_name.split("@")[-1] == self.classname: |
| 247 | self.funcname = func_name.split("@")[0] |
| 248 | args = ast.arguments(posonlyargs = [], args = [], vararg = ast.arg(arg = "args"), kwonlyargs = [], kw_defaults = [], kwarg = None, defaults = []) |
| 249 | init_statement = ast.Assign(targets = [ast.Name(id = "s", ctx = ast.Store)], value = ast.Call(func = ast.Name(id = self.classname, ctx = ast.Load), args = [], keywords = []), type_comment = None) |
| 250 | ast.fix_missing_locations(init_statement) |
| 251 | call_statement = ast.Expr(value = ast.Call(func = ast.Attribute(value = ast.Name(id = "s", ctx = ast.Load), attr = self.funcname, ctx = ast.Store), args = [ast.Starred(value = ast.Name(id = "args", ctx = ast.Load))], keywords = [])) |
| 252 | ast.fix_missing_locations(call_statement) |
| 253 | statements = [init_statement, call_statement] |
| 254 | new_node = ast.FunctionDef(name = "solution", args = args, body = statements, decorator_list =[], returns = None, type_comment = None, type_params = []) |
| 255 | ast.fix_missing_locations(new_node) |
| 256 | self.root.body = self.root.body + [new_node] |
| 257 | return ast.unparse(self.root), False |
| 258 | elif (len(self.visitor.funcs) > 0 and self.visitor.only_func) or self.force_rename: |
| 259 | if no_modify: |
| 260 | return ast.unparse(self.root), False |
| 261 | self.mode = "funcname" |
| 262 | self.visit(self.root) |
| 263 | return ast.unparse(self.root), False |
| 264 | else: |
| 265 | return self.code, True |
| 266 | except Exception as e: |
| 267 | #print(e) |
| 268 | #traceback.print_exc() |
| 269 | return -1, False |
| 270 | |
| 271 | |
| 272 |
no test coverage detected