Skip to content

Commit

Permalink
Merge pull request #582 from python-rope/lieryan-rope-base-ast-3
Browse files Browse the repository at this point in the history
rope.base.ast and rope.base.astutils
  • Loading branch information
lieryan committed Dec 10, 2022
2 parents cafdc69 + 4209cd5 commit a8fb5bd
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 14 deletions.
7 changes: 3 additions & 4 deletions rope/base/ast.py
@@ -1,19 +1,18 @@
import ast
from ast import *
from ast import * # noqa: F401,F403

from rope.base import fscommands


def parse(source, filename="<string>"):
# NOTE: the raw string should be given to `compile` function
def parse(source, filename="<string>", *args, **kwargs): # type: ignore
if isinstance(source, str):
source = fscommands.unicode_to_file_data(source)
if b"\r" in source:
source = source.replace(b"\r\n", b"\n").replace(b"\r", b"\n")
if not source.endswith(b"\n"):
source += b"\n"
try:
return ast.parse(source, filename="<unknown>")
return ast.parse(source, filename=filename, *args, **kwargs)
except (TypeError, ValueError) as e:
error = SyntaxError()
error.lineno = 1
Expand Down
4 changes: 2 additions & 2 deletions rope/base/evaluate.py
Expand Up @@ -7,7 +7,7 @@
from rope.base import (
arguments,
ast,
astutils,
nameanalyze,
exceptions,
pyobjects,
pyobjectsdef,
Expand Down Expand Up @@ -364,7 +364,7 @@ def _Lambda(self, node):

def _get_evaluated_names(targets, assigned, module, evaluation, lineno):
result = {}
for name, levels in astutils.get_name_levels(targets):
for name, levels in nameanalyze.get_name_levels(targets):
assignment = rope.base.pynames.AssignmentValue(assigned, levels, evaluation)
# XXX: this module should not access `rope.base.pynamesdef`!
pyname = rope.base.pynamesdef.AssignedName(lineno, module)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions rope/base/oi/soa.py
@@ -1,7 +1,7 @@
import rope.base.ast
import rope.base.oi.soi
import rope.base.pynames
from rope.base import pyobjects, evaluate, astutils, arguments
from rope.base import pyobjects, evaluate, nameanalyze, arguments


def analyze_module(pycore, pymodule, should_analyze, search_subscopes, followed_calls):
Expand Down Expand Up @@ -139,7 +139,7 @@ def _evaluate_assign_value(self, node, nodes, type_hint=False):
# IDEA: handle `__setslice__`, too


class _SOAAssignVisitor(astutils._NodeNameCollector):
class _SOAAssignVisitor(nameanalyze._NodeNameCollector):
def __init__(self):
super().__init__()
self.nodes = []
Expand Down
2 changes: 1 addition & 1 deletion rope/base/oi/type_hinting/providers/numpydocstrings.py
Expand Up @@ -4,7 +4,7 @@
Thanks to @davidhalter for this utils under MIT License.
"""
import re
from ast import literal_eval
from rope.base.ast import literal_eval
from rope.base.oi.type_hinting.providers import docstrings

try:
Expand Down
8 changes: 4 additions & 4 deletions rope/base/pyobjectsdef.py
Expand Up @@ -8,7 +8,7 @@
pynamesdef,
exceptions,
ast,
astutils,
nameanalyze,
pyobjects,
fscommands,
arguments,
Expand Down Expand Up @@ -313,7 +313,7 @@ def _Name(self, node):
self._assigned(node.id, assignment)

def _Tuple(self, node):
names = astutils.get_name_levels(node)
names = nameanalyze.get_name_levels(node)
for name, levels in names:
assignment = None
if self.assigned_ast is not None:
Expand Down Expand Up @@ -381,7 +381,7 @@ def _Name(self, node):
self._assigned(node.id, assignment)

def _Tuple(self, node):
names = astutils.get_name_levels(node)
names = nameanalyze.get_name_levels(node)
for name, levels in names:
assignment = None
if self.assigned_ast is not None:
Expand Down Expand Up @@ -479,7 +479,7 @@ def _update_evaluated(
assignment = pynamesdef.AssignmentValue(assigned, [], evaluation, eval_type)
self._assigned(targets, assignment)
else:
names = astutils.get_name_levels(targets)
names = nameanalyze.get_name_levels(targets)
for name, levels in names:
assignment = pynamesdef.AssignmentValue(
assigned, levels, evaluation, eval_type
Expand Down
2 changes: 1 addition & 1 deletion rope/refactor/occurrences.py
Expand Up @@ -35,9 +35,9 @@
arguments
"""

import ast
import re

from rope.base import ast
from rope.base import codeanalyze
from rope.base import evaluate
from rope.base import exceptions
Expand Down

0 comments on commit a8fb5bd

Please sign in to comment.