Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: remove rope.base.utils.pycompat #549

Merged
merged 4 commits into from Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 5 additions & 9 deletions rope/base/builtins.py
@@ -1,4 +1,5 @@
"""This module tries to support builtin types and functions."""
import ast
import inspect
import io

Expand All @@ -8,7 +9,6 @@
raw_input = input

import rope.base.evaluate
from rope.base.utils import pycompat
from rope.base import pynames, pyobjects, arguments, utils


Expand Down Expand Up @@ -720,15 +720,11 @@ def get_name(self):
return "lambda"

def get_param_names(self, special_args=True):
result = [
pycompat.get_ast_arg_arg(node)
for node in self.arguments.args
if isinstance(node, pycompat.ast_arg_type)
]
result = [node.arg for node in self.arguments.args if isinstance(node, ast.arg)]
if self.arguments.vararg:
result.append("*" + pycompat.get_ast_arg_arg(self.arguments.vararg))
result.append("*" + self.arguments.vararg.arg)
if self.arguments.kwarg:
result.append("**" + pycompat.get_ast_arg_arg(self.arguments.kwarg))
result.append("**" + self.arguments.kwarg.arg)
return result

@property
Expand Down Expand Up @@ -869,4 +865,4 @@ def _input_function(args):
),
}

builtins = BuiltinModule(pycompat.builtins.__name__, initial=_initial_builtins)
builtins = BuiltinModule("builtins", initial=_initial_builtins)
2 changes: 0 additions & 2 deletions rope/base/fscommands.py
Expand Up @@ -10,8 +10,6 @@
import os
import shutil
import subprocess

import rope.base.utils.pycompat as pycompat
import typing


Expand Down
5 changes: 3 additions & 2 deletions rope/base/oi/runmod.py
Expand Up @@ -11,7 +11,6 @@ def __rope_start_everything():
import inspect
import types
import threading
import rope.base.utils.pycompat as pycompat
import base64
import hashlib
import hmac
Expand Down Expand Up @@ -231,7 +230,9 @@ def _realpath(path):
if send_info != "-":
data_sender = _FunctionCallDataSender(send_info, project_root)
del sys.argv[1:4]
pycompat.execfile(file_to_run, run_globals)
with open(file_to_run) as f:
code = compile(f.read(), file_to_run, "exec")
exec(code, run_globals)
if send_info != "-":
data_sender.close()

Expand Down
1 change: 0 additions & 1 deletion rope/base/oi/type_hinting/evaluate.py
@@ -1,7 +1,6 @@
# Based on super lightweight Simple Top-Down Parser from http://effbot.org/zone/simple-top-down-parsing.htm
# and https://bitbucket.org/emacsway/sqlbuilder/src/default/sqlbuilder/smartsql/contrib/evaluate.py
import re
from rope.base.utils import pycompat
from rope.base.oi.type_hinting import utils
from rope.base import utils as base_utils

Expand Down
1 change: 0 additions & 1 deletion rope/base/oi/type_hinting/utils.py
Expand Up @@ -8,7 +8,6 @@
from rope.base import evaluate
from rope.base.exceptions import AttributeNotFoundError
from rope.base.pyobjects import PyClass, PyDefinedObject, PyFunction, PyObject
from rope.base.utils import pycompat


def get_super_func(pyfunc):
Expand Down
6 changes: 3 additions & 3 deletions rope/base/prefs.py
Expand Up @@ -6,9 +6,7 @@
from packaging.requirements import Requirement
from pytoolconfig import PyToolConfig, UniversalKey, field
from pytoolconfig.sources import Source

from rope.base.resources import Folder
from rope.base.utils import pycompat


@dataclass
Expand Down Expand Up @@ -258,7 +256,9 @@ def _read(self) -> bool:
"__file__": config.real_path,
}
)
pycompat.execfile(config.real_path, self.run_globals)
with open(config.real_path) as f:
code = compile(f.read(),config.real_path, 'exec')
lieryan marked this conversation as resolved.
Show resolved Hide resolved
exec(code, self.run_globals)
return True

def parse(self) -> Optional[Dict]:
Expand Down
22 changes: 7 additions & 15 deletions rope/base/pyobjectsdef.py
@@ -1,4 +1,3 @@
from rope.base.pynames import DefinedName
import rope.base.builtins
import rope.base.codeanalyze
import rope.base.evaluate
Expand All @@ -15,7 +14,6 @@
arguments,
utils,
)
from rope.base.utils import pycompat


class PyFunction(pyobjects.PyFunction):
Expand Down Expand Up @@ -79,16 +77,12 @@ def get_name(self):

def get_param_names(self, special_args=True):
# TODO: handle tuple parameters
result = [
pycompat.get_ast_arg_arg(node)
for node in self.arguments.args
if isinstance(node, pycompat.ast_arg_type)
]
result = [node.arg for node in self.arguments.args if isinstance(node, ast.arg)]
if special_args:
if self.arguments.vararg:
result.append(pycompat.get_ast_arg_arg(self.arguments.vararg))
result.append(self.arguments.vararg.arg)
if self.arguments.kwarg:
result.append(pycompat.get_ast_arg_arg(self.arguments.kwarg))
result.append(self.arguments.kwarg.arg)
return result

def get_kind(self):
Expand Down Expand Up @@ -461,9 +455,7 @@ def _AugAssign(self, node):
pass

def _For(self, node):
names = self._update_evaluated(
node.target, node.iter, ".__iter__().next()" # noqa
)
self._update_evaluated(node.target, node.iter, ".__iter__().next()") # noqa
for child in node.body + node.orelse:
ast.walk(child, self)

Expand Down Expand Up @@ -496,7 +488,7 @@ def _update_evaluated(
return result

def _With(self, node):
for item in pycompat.get_ast_with_items(node):
for item in node.items:
if item.optional_vars:
self._update_evaluated(
item.optional_vars, item.context_expr, ".__enter__()"
Expand Down Expand Up @@ -600,8 +592,8 @@ def _FunctionDef(self, node):
if len(node.args.args) > 0:
first = node.args.args[0]
new_visitor = None
if isinstance(first, pycompat.ast_arg_type):
new_visitor = _ClassInitVisitor(self, pycompat.get_ast_arg_arg(first))
if isinstance(first, ast.arg):
new_visitor = _ClassInitVisitor(self, first.arg)
if new_visitor is not None:
for child in ast.get_child_nodes(node):
ast.walk(child, new_visitor)
Expand Down
21 changes: 0 additions & 21 deletions rope/base/utils/pycompat.py

This file was deleted.

11 changes: 3 additions & 8 deletions rope/refactor/extract.py
Expand Up @@ -5,7 +5,6 @@
from rope.base import ast, codeanalyze
from rope.base.change import ChangeSet, ChangeContents
from rope.base.exceptions import RefactoringError
from rope.base.utils import pycompat
from rope.base.utils.datastructures import OrderedSet
from rope.refactor import sourceutils, similarfinder, patchedast, suites, usefunction

Expand Down Expand Up @@ -948,15 +947,11 @@ def _handle_loop_context(self, node):


def _get_argnames(arguments):
result = [
pycompat.get_ast_arg_arg(node)
for node in arguments.args
if isinstance(node, pycompat.ast_arg_type)
]
result = [node.arg for node in arguments.args if isinstance(node, ast.arg)]
if arguments.vararg:
result.append(pycompat.get_ast_arg_arg(arguments.vararg))
result.append(vararg.arg)
if arguments.kwarg:
result.append(pycompat.get_ast_arg_arg(arguments.kwarg))
result.append(arguments.kwarg.arg)
return result


Expand Down
13 changes: 4 additions & 9 deletions rope/refactor/patchedast.py
Expand Up @@ -5,13 +5,8 @@
from itertools import chain

from rope.base import ast, codeanalyze, exceptions
from rope.base.utils import pycompat


try:
basestring
except NameError:
basestring = (str, bytes)
basestring = (str, bytes)

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

Expand Down Expand Up @@ -574,11 +569,11 @@ def _arguments(self, node):
if node.vararg is not None:
if args:
children.append(",")
children.extend(["*", pycompat.get_ast_arg_arg(node.vararg)])
children.extend(["*", node.vararg.arg])
if node.kwarg is not None:
if args or node.vararg is not None:
children.append(",")
children.extend(["**", pycompat.get_ast_arg_arg(node.kwarg)])
children.extend(["**", node.kwarg.arg])
self._handle(node, children)

def _add_args_to_children(self, children, arg, default):
Expand Down Expand Up @@ -853,7 +848,7 @@ def _handle_with_node(self, node, is_async):

if is_async:
children.extend(["async"])
for item in pycompat.get_ast_with_items(node):
for item in node.items:
children.extend([self.with_or_comma_context_manager, item.context_expr])
if item.optional_vars:
children.extend(["as", item.optional_vars])
Expand Down
1 change: 0 additions & 1 deletion rope/refactor/suites.py
@@ -1,7 +1,6 @@
from itertools import chain

from rope.base import ast
from rope.base.utils import pycompat


def find_visible(node, lines):
Expand Down
1 change: 0 additions & 1 deletion ropetest/advanced_oi_test.py
Expand Up @@ -6,7 +6,6 @@

import rope.base.libutils
import rope.base.oi
from rope.base.utils import pycompat
from ropetest import testutils


Expand Down
5 changes: 2 additions & 3 deletions ropetest/refactor/patchedasttest.py
Expand Up @@ -3,7 +3,6 @@
from textwrap import dedent

from rope.base import ast
from rope.base.utils import pycompat
from rope.refactor import patchedast
from ropetest import testutils

Expand Down Expand Up @@ -586,7 +585,7 @@ def f(p1, **p2):
"Function",
["def", " ", "f", "", "(", "", "arguments", "", ")", "", ":", "\n ", "Expr", "\n ", "Pass"],
)
expected_child = pycompat.ast_arg_type.__name__
expected_child = ast.arg.__name__
checker.check_children(
"arguments", [expected_child, "", ",", " ", "**", "", "p2"]
)
Expand Down Expand Up @@ -838,7 +837,7 @@ def test_lambda_node(self):
checker.check_children(
"Lambda", ["lambda", " ", "arguments", "", ":", " ", NameConstant]
)
expected_child = pycompat.ast_arg_type.__name__
expected_child = ast.arg.__name__
checker.check_children(
"arguments",
[expected_child, "", ",", " ", expected_child, "", "=", "", "Num", "", ",", " ", "*", "", "z"],
Expand Down