def find_temps(project, code): code = "def f():\n" + sourceutils.indent_lines(code, 4) pymodule = libutils.get_string_module(project, code) result = [] function_scope = pymodule.get_scope().get_scopes()[0] for name, pyname in function_scope.get_names().items(): if isinstance(pyname, pynames.AssignedName): result.append(name) return result
def find_temps(project, code): code = 'def f():\n' + sourceutils.indent_lines(code, 4) pymodule = project.pycore.get_string_module(code) result = [] function_scope = pymodule.get_scope().get_scopes()[0] for name, pyname in function_scope.get_names().items(): if isinstance(pyname, pynames.AssignedName): result.append(name) return result
def _get_factory_method(self, lines, class_scope, factory_name, global_): unit_indents = ' ' * sourceutils.get_indent(self.pycore) if global_: if self._get_scope_indents(lines, class_scope) > 0: raise rope.base.exceptions.RefactoringError( 'Cannot make global factory method for nested classes.') return ('\ndef %s(*args, **kwds):\n%sreturn %s(*args, **kwds)\n' % (factory_name, unit_indents, self.old_name)) unindented_factory = \ ('@staticmethod\ndef %s(*args, **kwds):\n' % factory_name + '%sreturn %s(*args, **kwds)\n' % (unit_indents, self.old_name)) indents = self._get_scope_indents(lines, class_scope) + \ sourceutils.get_indent(self.pycore) return '\n' + sourceutils.indent_lines(unindented_factory, indents)
def _get_function_definition(self): args = self._find_function_arguments() returns = self._find_function_returns() result = [] if self.info.method and not self.info.make_global and \ _get_function_kind(self.info.scope) != 'method': result.append('@staticmethod\n') result.append('def %s:\n' % self._get_function_signature(args)) unindented_body = self._get_unindented_function_body(returns) indents = sourceutils.get_indent(self.info.project) function_body = sourceutils.indent_lines(unindented_body, indents) result.append(function_body) definition = ''.join(result) return definition + '\n'
def _get_factory_method(self, lines, class_scope, factory_name, global_): unit_indents = " " * sourceutils.get_indent(self.project) if global_: if self._get_scope_indents(lines, class_scope) > 0: raise rope.base.exceptions.RefactoringError( "Cannot make global factory method for nested classes.") return "\ndef %s(*args, **kwds):\n%sreturn %s(*args, **kwds)\n" % ( factory_name, unit_indents, self.old_name, ) unindented_factory = ( "@staticmethod\ndef %s(*args, **kwds):\n" % factory_name + "%sreturn %s(*args, **kwds)\n" % (unit_indents, self.old_name)) indents = self._get_scope_indents( lines, class_scope) + sourceutils.get_indent(self.project) return "\n" + sourceutils.indent_lines(unindented_factory, indents)