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: Second round: clean imports and qualifiers #584

Merged
merged 17 commits into from Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from 16 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
8 changes: 7 additions & 1 deletion rope/base/builtins.py
Expand Up @@ -3,7 +3,13 @@
import io

import rope.base.evaluate
from rope.base import ast, pynames, pyobjects, arguments, utils
from rope.base import (
arguments,
ast,
pynames,
pyobjects,
utils,
)


try:
Expand Down
24 changes: 14 additions & 10 deletions rope/base/oi/soa.py
@@ -1,7 +1,13 @@
import rope.base.ast
import rope.base.oi.soi
import rope.base.pynames
from rope.base import pyobjects, evaluate, astutils, arguments
import rope.base.ast # Use fully qualified names for clarity.
import rope.base.builtins # Use fully qualified names for clarity.
from rope.base import (
arguments,
astutils,
evaluate,
pynames,
pyobjects,
)
from rope.base.oi import soi


def analyze_module(pycore, pymodule, should_analyze, search_subscopes, followed_calls):
Expand Down Expand Up @@ -63,7 +69,7 @@ def _Call(self, node):
pyclass = pyfunction
if "__init__" in pyfunction:
pyfunction = pyfunction["__init__"].get_object()
pyname = rope.base.pynames.UnboundName(pyobjects.PyObject(pyclass))
pyname = pynames.UnboundName(pyobjects.PyObject(pyclass))
args = self._args_with_self(primary, pyname, pyfunction, node)
elif "__call__" in pyfunction:
pyfunction = pyfunction["__call__"].get_object()
Expand Down Expand Up @@ -123,13 +129,11 @@ def _evaluate_assign_value(self, node, nodes, type_hint=False):
for subscript, levels in nodes:
instance = evaluate.eval_node(self.scope, subscript.value)
args_pynames = [evaluate.eval_node(self.scope, subscript.slice)]
value = rope.base.oi.soi._infer_assignment(
rope.base.pynames.AssignmentValue(
node.value, levels, type_hint=type_hint
),
value = soi._infer_assignment(
pynames.AssignmentValue(node.value, levels, type_hint=type_hint),
self.pymodule,
)
args_pynames.append(rope.base.pynames.UnboundName(value))
args_pynames.append(pynames.UnboundName(value))
if instance is not None and value is not None:
pyobject = instance.get_object()
if "__setitem__" in pyobject:
Expand Down
40 changes: 21 additions & 19 deletions rope/base/oi/soi.py
Expand Up @@ -4,14 +4,18 @@
package.

"""
import rope.base.builtins
import rope.base.pynames
import rope.base.pyobjects
from rope.base import arguments, evaluate, utils
import rope.base.builtins # Use full qualification for clarity.
from rope.base import (
arguments,
evaluate,
pynames,
pyobjects,
utils,
)
from rope.base.oi.type_hinting.factory import get_type_hinting_factory


_ignore_inferred = utils.ignore_exception(rope.base.pyobjects.IsBeingInferredError)
_ignore_inferred = utils.ignore_exception(pyobjects.IsBeingInferredError)


@_ignore_inferred
Expand All @@ -35,7 +39,7 @@ def infer_returned_object(pyfunction, args):
).make_return_provider()
type_ = hint_return(pyfunction)
if type_ is not None:
return rope.base.pyobjects.PyObject(type_)
return pyobjects.PyObject(type_)


@_ignore_inferred
Expand All @@ -56,9 +60,9 @@ def _handle_first_parameter(pyobject, parameters):
if not parameters:
if not pyobject.get_param_names(special_args=False):
return
parameters.append(rope.base.pyobjects.get_unknown())
parameters.append(pyobjects.get_unknown())
if kind == "method":
parameters[0] = rope.base.pyobjects.PyObject(pyobject.parent)
parameters[0] = pyobjects.PyObject(pyobject.parent)
if kind == "classmethod":
parameters[0] = pyobject.parent

Expand All @@ -74,7 +78,7 @@ def infer_assigned_object(pyname):
and result.get_name() == "NotImplementedType"
):
break
elif result == rope.base.pyobjects.get_unknown():
elif result == pyobjects.get_unknown():
break
elif result is not None:
return result
Expand All @@ -84,7 +88,7 @@ def infer_assigned_object(pyname):
).make_assignment_provider()
hinting_result = hint_assignment(pyname)
if hinting_result is not None:
return rope.base.pyobjects.PyObject(hinting_result)
return pyobjects.PyObject(hinting_result)
return result


Expand Down Expand Up @@ -117,13 +121,13 @@ def _infer_returned(pyobject, args):
if resulting_pyname is None:
continue
pyobject = resulting_pyname.get_object()
if pyobject == rope.base.pyobjects.get_unknown():
if pyobject == pyobjects.get_unknown():
continue
if not scope._is_generator():
return pyobject
else:
return rope.base.builtins.get_generator(pyobject)
except rope.base.pyobjects.IsBeingInferredError:
except pyobjects.IsBeingInferredError:
pass


Expand All @@ -134,9 +138,9 @@ def _parameter_objects(pyobject):
for name in params:
type_ = hint_param(pyobject, name)
if type_ is not None:
result.append(rope.base.pyobjects.PyObject(type_))
result.append(pyobjects.PyObject(type_))
else:
result.append(rope.base.pyobjects.get_unknown())
result.append(pyobjects.get_unknown())
return result


Expand Down Expand Up @@ -185,9 +189,7 @@ def _follow_pyname(assignment, pymodule, lineno=None):
isinstance(result.get_type(), rope.base.builtins.Property)
and holding_scope.get_kind() == "Class"
):
arg = rope.base.pynames.UnboundName(
rope.base.pyobjects.PyObject(holding_scope.pyobject)
)
arg = pynames.UnboundName(pyobjects.PyObject(holding_scope.pyobject))
return pyname, result.get_type().get_property_object(
arguments.ObjectArguments([arg])
)
Expand All @@ -208,15 +210,15 @@ def _follow_evaluations(assignment, pyname, pyobject):
if new_pyname is not None:
pyobject = new_pyname.get_object()
if pyobject is not None and call:
if isinstance(pyobject, rope.base.pyobjects.AbstractFunction):
if isinstance(pyobject, pyobjects.AbstractFunction):
args = arguments.ObjectArguments([pyname])
pyobject = pyobject.get_returned_object(args)
else:
pyobject = None
if pyobject is None:
break
if pyobject is not None and assignment.assign_type:
return rope.base.pyobjects.PyObject(pyobject)
return pyobjects.PyObject(pyobject)
return pyobject


Expand Down
2 changes: 1 addition & 1 deletion rope/base/oi/transform.py
Expand Up @@ -2,7 +2,7 @@
import os
import re

import rope.base.builtins
import rope.base.builtins # Use full qualification for clarity.
from rope.base import exceptions


Expand Down
5 changes: 1 addition & 4 deletions rope/base/oi/type_hinting/utils.py
@@ -1,9 +1,6 @@
import logging
from typing import Union, Optional

try:
from typing import Union, Optional
except ImportError:
pass
import rope.base.utils as base_utils
from rope.base import evaluate
from rope.base.exceptions import AttributeNotFoundError
Expand Down
12 changes: 9 additions & 3 deletions rope/base/project.py
Expand Up @@ -3,12 +3,18 @@
import sys
import warnings

import rope.base.fscommands
import rope.base.resourceobserver as resourceobserver
from rope.base import exceptions, history, pycore, taskhandle, utils
import rope.base.fscommands # Use full qualification for clarity.
from rope.base import (
exceptions,
history,
pycore,
taskhandle,
utils,
)
from rope.base.exceptions import ModuleNotFoundError
from rope.base.prefs import Prefs, get_config
from rope.base.resources import File, Folder, _ResourceMatcher
import rope.base.resourceobserver as resourceobserver

try:
import cPickle as pickle
Expand Down