Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rope/base/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from rope.base import fscommands


def parse(source, filename="<string>", *args, **kwargs): # type: ignore
def rope_parse(source, filename="<string>", *args, **kwargs): # type: ignore
if isinstance(source, str):
source = fscommands.unicode_to_file_data(source)
if b"\r" in source:
Expand Down
3 changes: 2 additions & 1 deletion rope/base/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
pyobjectsdef,
worder,
)
from rope.base.ast import rope_parse

BadIdentifierError = exceptions.BadIdentifierError

Expand Down Expand Up @@ -49,7 +50,7 @@ def eval_str(holding_scope, name):
def eval_str2(holding_scope, name):
try:
# parenthesizing for handling cases like 'a_var.\nattr'
node = ast.parse("(%s)" % name)
node = rope_parse("(%s)" % name)
except SyntaxError:
raise BadIdentifierError("Not a resolvable python identifier selected.")
return eval_node2(holding_scope, node)
Expand Down
7 changes: 4 additions & 3 deletions rope/base/pyobjectsdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
pyobjects,
utils,
)
from rope.base.ast import rope_parse


class PyFunction(pyobjects.PyFunction):
Expand Down Expand Up @@ -177,7 +178,7 @@ def __init__(self, pycore, source=None, resource=None, force_errors=False):
raise
else:
source = "\n"
node = ast.parse("\n")
node = rope_parse("\n")
self.source_code = source
self.star_imports = []
self.visitor_class = _GlobalVisitor
Expand All @@ -197,7 +198,7 @@ def _init_source(self, pycore, source_code, resource):
source_bytes = fscommands.unicode_to_file_data(source_code)
else:
source_bytes = source_code
ast_node = ast.parse(source_bytes, filename=filename)
ast_node = rope_parse(source_bytes, filename=filename)
except SyntaxError as e:
raise exceptions.ModuleSyntaxError(filename, e.lineno, e.msg)
except UnicodeDecodeError as e:
Expand Down Expand Up @@ -239,7 +240,7 @@ def __init__(self, pycore, resource=None, force_errors=False):
init_dot_py, force_errors=force_errors
).get_ast()
else:
ast_node = ast.parse("\n")
ast_node = rope_parse("\n")
super().__init__(pycore, ast_node, resource)

def _create_structural_attributes(self):
Expand Down
2 changes: 1 addition & 1 deletion rope/refactor/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ def _get_function_kind(scope):
def _parse_text(body):
body = sourceutils.fix_indentation(body, 0)
try:
node = ast.parse(body)
node = ast.parse(body) # stdlib.ast.parse.
except SyntaxError:
# needed to parse expression containing := operator
try:
Expand Down
3 changes: 2 additions & 1 deletion rope/refactor/occurrences.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
utils,
worder,
)
from rope.base.ast import rope_parse


class Finder:
Expand Down Expand Up @@ -339,7 +340,7 @@ def _re_search(self, source):
yield match.start("fstring") + occurrence_node.col_offset

def _search_in_f_string(self, f_string):
tree = ast.parse(f_string)
tree = rope_parse(f_string)
for node in ast.walk(tree):
if isinstance(node, ast.Name) and node.id == self.name:
yield node
Expand Down
5 changes: 4 additions & 1 deletion rope/refactor/patchedast.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

from rope.base import ast, codeanalyze, exceptions

# To do: PR #633: remove call_for_nodes.
from rope.base.ast import call_for_nodes, rope_parse

COMMA_IN_WITH_PATTERN = re.compile(r"\(.*?\)|(,)")


Expand All @@ -15,7 +18,7 @@ def get_patched_ast(source, sorted_children=False):
Adds ``sorted_children`` field only if `sorted_children` is True.

"""
return patch_ast(ast.parse(source), source, sorted_children)
return patch_ast(rope_parse(source), source, sorted_children)


def patch_ast(node, source, sorted_children=False):
Expand Down
7 changes: 4 additions & 3 deletions rope/refactor/similarfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import rope.base.builtins # Use full qualification for clarity.
import rope.refactor.wildcards # Use full qualification for clarity.
from rope.base import ast, codeanalyze, exceptions, libutils
from rope.base.ast import rope_parse
from rope.refactor import patchedast
from rope.refactor.patchedast import MismatchedTokenError

Expand Down Expand Up @@ -73,10 +74,10 @@ class RawSimilarFinder:
def __init__(self, source, node=None, does_match=None):
if node is None:
try:
node = ast.parse(source)
node = rope_parse(source)
except SyntaxError:
# needed to parse expression containing := operator
node = ast.parse("(" + source + ")")
node = rope_parse("(" + source + ")")
if does_match is None:
self.does_match = self._simple_does_match
else:
Expand Down Expand Up @@ -120,7 +121,7 @@ def _get_matched_asts(self, code):

def _create_pattern(self, expression):
expression = self._replace_wildcards(expression)
node = ast.parse(expression)
node = rope_parse(expression)
# Getting Module.Stmt.nodes
nodes = node.body
if len(nodes) == 1 and isinstance(nodes[0], ast.Expr):
Expand Down
4 changes: 2 additions & 2 deletions ropetest/refactor/suitestest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from textwrap import dedent

from rope.base import ast
from rope.base.ast import rope_parse
from rope.refactor import suites
from ropetest import testutils

Expand Down Expand Up @@ -217,4 +217,4 @@ def test_match_case(self):


def source_suite_tree(source):
return suites.ast_suite_tree(ast.parse(source))
return suites.ast_suite_tree(rope_parse(source))