How to use the rope.base.ast function in rope

To help you get started, we’ve selected a few rope examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JulianEberius / SublimePythonIDE / server / lib / python3 / rope / refactor / similarfinder.py View on Github external
def _get_children(self, node):
        """Return not `ast.expr_context` children of `node`"""
        children = ast.get_children(node)
        return [child for child in children
                if not isinstance(child, ast.expr_context)]
github DonJayamanne / pythonVSCode / pythonFiles / rope / refactor / extract.py View on Github external
def _parse_text(body):
    body = sourceutils.fix_indentation(body, 0)
    node = ast.parse(body)
    return node
github gtt116 / vimrc / vim / bundle / python-mode / submodules / rope / rope / refactor / importutils / module_imports.py View on Github external
def _Attribute(self, node):
        result = []
        while isinstance(node, ast.Attribute):
            result.append(node.attr)
            node = node.value
        if isinstance(node, ast.Name):
            result.append(node.id)
            primary = '.'.join(reversed(result))
            if self._get_root()._is_node_interesting(node) and \
               not self.is_bound(primary):
                self.add_unbound(primary)
        else:
            ast.walk(node, self)
github python-rope / rope / rope / base / pyobjectsdef.py View on Github external
def _For(self, node):
        names = self._update_evaluated(node.target, node.iter,  # noqa
                                       '.__iter__().next()')
        for child in node.body + node.orelse:
            ast.walk(child, self)
github gtt116 / vimrc / vim / bundle / python-mode / submodules / rope / rope / refactor / patchedast.py View on Github external
'Node <%s> has been already patched; please report!' %
                node.__class__.__name__, RuntimeWarning)
            return
        base_children = collections.deque(base_children)
        self.children_stack.append(base_children)
        children = collections.deque()
        formats = []
        suspected_start = self.source.offset
        start = suspected_start
        first_token = True
        while base_children:
            child = base_children.popleft()
            if child is None:
                continue
            offset = self.source.offset
            if isinstance(child, ast.AST):
                ast.call_for_nodes(child, self)
                token_start = child.region[0]
            else:
                if child is self.String:
                    region = self.source.consume_string(
                        end=self._find_next_statement_start())
                elif child is self.Number:
                    region = self.source.consume_number()
                elif child == '!=':
                    # INFO: This has been added to handle deprecated ``<>``
                    region = self.source.consume_not_equal()
                elif child == self.semicolon_or_as_in_except:
                    # INFO: This has been added to handle deprecated
                    # semicolon in except
                    region = self.source.consume_except_as_or_semicolon()
                else:
github JulianEberius / SublimePythonIDE / server / lib / python3 / rope / refactor / extract.py View on Github external
def _handle_conditional_node(self, node):
        self.conditional = True
        try:
            for child in ast.get_child_nodes(node):
                ast.walk(child, self)
        finally:
            self.conditional = False
github JulianEberius / SublimePythonIDE / server / lib / python3 / rope / refactor / similarfinder.py View on Github external
def _check_statements(self, node):
        for child in ast.get_children(node):
            if isinstance(child, (list, tuple)):
                self.__check_stmt_list(child)
github spyder-ide / spyder / external-py2 / rope / base / arguments.py View on Github external
def get_pynames(self, parameters):
        result = [None] * max(len(parameters), len(self.args))
        for index, arg in enumerate(self.args):
            if isinstance(arg, ast.keyword) and arg.arg in parameters:
                result[parameters.index(arg.arg)] = self._evaluate(arg.value)
            else:
                result[index] = self._evaluate(arg)
        return result
github marslo / myvim / Configurations / Offline_Packages / bundle / python-mode / pymode / libs / rope / refactor / importutils / module_imports.py View on Github external
def _first_import_line(self):
        nodes = self.pymodule.get_ast().body
        lineno = 0
        if self.pymodule.get_doc() is not None:
            lineno = 1
        if len(nodes) > lineno:
            if (isinstance(nodes[lineno], ast.Import) or
                isinstance(nodes[lineno], ast.ImportFrom)):
                return nodes[lineno].lineno
            lineno = self.pymodule.logical_lines.logical_line_in(
                nodes[lineno].lineno)[0]
        else:
            lineno = self.pymodule.lines.length()

        return lineno - _count_blank_lines(self.pymodule.lines.get_line,
                                           lineno - 1, 1, -1)
github marslo / myvim / Configurations / Offline_Packages / bundle / python-mode / pymode / libs / rope / refactor / restructure.py View on Github external
def _get_nearest_roots(self, node):
        if node not in self._nearest_roots:
            result = []
            for child in ast.get_child_nodes(node):
                if child in self.matched_asts:
                    result.append(child)
                else:
                    result.extend(self._get_nearest_roots(child))
            self._nearest_roots[node] = result
        return self._nearest_roots[node]