Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ce634dd
Simplify po.get_base_type & po.get_unknown. Remove PyObject staticmethod
edreamleo Feb 12, 2023
d2ee568
Remove disabled methods
edreamleo Feb 12, 2023
e18fc31
Add rope.base.utils.predicates.py
edreamleo Feb 12, 2023
e10f548
Use predicates (almost?) everywhere
edreamleo Feb 12, 2023
db8826a
Remove last mentions of Abstract classes
edreamleo Feb 12, 2023
56aecfc
Remove another reference to an Abstract class
edreamleo Feb 12, 2023
e57ed11
Remove one last ref to an Abstract class
edreamleo Feb 12, 2023
3a1cae7
First successful version w/o Abstract classes
edreamleo Feb 13, 2023
d3f46b5
Cleanups
edreamleo Feb 13, 2023
c584054
Tweaks
edreamleo Feb 13, 2023
8da72cb
Convert ### comments to `# was...` comments.
edreamleo Feb 13, 2023
b16c27c
OMG! Single inheritance is so easy!
edreamleo Feb 13, 2023
7fca6bf
Single inheritance! PyDefinedObject is a PyObject
edreamleo Feb 13, 2023
3dd8127
Use super().__init__ where possible
edreamleo Feb 13, 2023
740aa8e
Annotate resolve_type w/o a union!
edreamleo Feb 13, 2023
6ca16a7
One more super().__init__
edreamleo Feb 13, 2023
a040a0f
Remove redundant base class
edreamleo Feb 13, 2023
b20ec1b
Add two methods from AbstractFunction, per mypy warning
edreamleo Feb 13, 2023
c9c277a
Add one method from AbstractClass
edreamleo Feb 13, 2023
c34f711
Move predicates to pyobjects.py
edreamleo Feb 13, 2023
e646a11
Remove predicates.py
edreamleo Feb 13, 2023
28e4540
Add a comment
edreamleo Feb 13, 2023
c88d487
Add notes and trace
edreamleo Feb 13, 2023
b296b09
Merge master into this branch, preferring master's code
edreamleo Mar 6, 2023
73c2713
Merge branch 'master' into ekr-abstract-predicates
edreamleo Mar 6, 2023
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
7 changes: 4 additions & 3 deletions rope/base/arguments.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import rope.base.evaluate
from rope.base import ast
from rope.base.pyobjects import is_abstract_class


class Arguments:
Expand Down Expand Up @@ -104,8 +105,8 @@ def _is_method_call(primary, pyfunction):
and isinstance(pyfunction.parent, rope.base.pyobjects.PyClass)
):
return True
if isinstance(
pyobject.get_type(), rope.base.pyobjects.AbstractClass
) and isinstance(pyfunction, rope.base.builtins.BuiltinFunction):
if is_abstract_class(pyobject.get_type()) and isinstance(
pyfunction, rope.base.builtins.BuiltinFunction
):
return True
return False
49 changes: 27 additions & 22 deletions rope/base/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

import rope.base.evaluate
from rope.base import arguments, ast, pynames, pyobjects, utils
from rope.base.pyobjects import get_base_type
from rope.base.pyobjects import is_abstract_class, is_abstract_function


class BuiltinModule(pyobjects.AbstractModule):
class BuiltinModule(pyobjects.PyObject): # was pyobjects.AbstractModule.
def __init__(self, name, pycore=None, initial={}):
super().__init__()
super().__init__(get_base_type("Module"))
self.name = name
self.pycore = pycore
self.initial = initial
Expand Down Expand Up @@ -68,10 +70,11 @@ def parent(self):
return self._parent


class BuiltinClass(_BuiltinElement, pyobjects.AbstractClass):
class BuiltinClass(_BuiltinElement, pyobjects.PyObject):
# was (_BuiltinElement, pyobjects.AbstractClass).
def __init__(self, builtin, attributes, parent=None):
pyobjects.PyObject.__init__(self, get_base_type("Type"))
_BuiltinElement.__init__(self, builtin, parent)
pyobjects.AbstractClass.__init__(self)
self.initial = attributes

@utils.saveit
Expand All @@ -83,13 +86,17 @@ def get_attributes(self):
def get_module(self):
return builtins

def get_superclasses(self):
return []

class BuiltinFunction(_BuiltinElement, pyobjects.AbstractFunction):

class BuiltinFunction(_BuiltinElement, pyobjects.PyObject):
# was (_BuiltinElement, pyobjects.AbstractFunction).
def __init__(
self, returned=None, function=None, builtin=None, argnames=[], parent=None
):
pyobjects.PyObject.__init__(self, get_base_type("Function"))
_BuiltinElement.__init__(self, builtin, parent)
pyobjects.AbstractFunction.__init__(self)
self.argnames = argnames
self.returned = returned
self.function = function
Expand Down Expand Up @@ -580,9 +587,9 @@ def get_definition_location(self):
return (None, None)


class Iterator(pyobjects.AbstractClass):
class Iterator(pyobjects.PyObject): # was pyobjects.AbstractClass
def __init__(self, holding=None):
super().__init__()
super().__init__(get_base_type("Type"))
self.holding = holding
self.attributes = {
"next": BuiltinName(BuiltinFunction(self.holding)),
Expand All @@ -599,9 +606,9 @@ def get_returned_object(self, args):
get_iterator = _create_builtin_getter(Iterator)


class Generator(pyobjects.AbstractClass):
class Generator(pyobjects.PyObject): # was pyobjects.AbstractClass.
def __init__(self, holding=None):
super().__init__()
super().__init__(get_base_type("Type"))
self.holding = holding
self.attributes = {
"next": BuiltinName(BuiltinFunction(self.holding)),
Expand Down Expand Up @@ -672,7 +679,7 @@ def __init__(self, fget=None, fset=None, fdel=None, fdoc=None):
super().__init__(property, attributes)

def get_property_object(self, args):
if isinstance(self._fget, pyobjects.AbstractFunction):
if is_abstract_function(self._fget):
return self._fget.get_returned_object(args)


Expand All @@ -681,9 +688,9 @@ def _property_function(args):
return pyobjects.PyObject(Property(parameters[0]))


class Lambda(pyobjects.AbstractFunction):
class Lambda(pyobjects.PyObject): # was pyobjects.AbstractFunction.
def __init__(self, node, scope):
super().__init__()
super().__init__(get_base_type("Function"))
self.node = node
self.arguments = node.args
self.scope = scope
Expand Down Expand Up @@ -743,7 +750,7 @@ def _infer_sequence_for_pyname(pyname):
args = arguments.ObjectArguments([pyname])
if "__iter__" in seq:
obj = seq["__iter__"].get_object()
if not isinstance(obj, pyobjects.AbstractFunction):
if not is_abstract_function(obj):
return None
iter = obj.get_returned_object(args)
if iter is not None and "next" in iter:
Expand Down Expand Up @@ -783,14 +790,12 @@ def _super_function(args):
passed_class, passed_self = args.get_arguments(["type", "self"])
if passed_self is None:
return passed_class
else:
# pyclass = passed_self.get_type()
pyclass = passed_class
if isinstance(pyclass, pyobjects.AbstractClass):
supers = pyclass.get_superclasses()
if supers:
return pyobjects.PyObject(supers[0])
return passed_self
pyclass = passed_class
if is_abstract_class(pyclass):
supers = pyclass.get_superclasses()
if supers:
return pyobjects.PyObject(supers[0])
return passed_self


def _zip_function(args):
Expand Down
22 changes: 10 additions & 12 deletions rope/base/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
ast,
exceptions,
nameanalyze,
pyobjects,
# pyobjects,
pyobjectsdef,
worder,
)
from rope.base.pyobjects import is_abstract_class, is_abstract_function

BadIdentifierError = exceptions.BadIdentifierError

Expand Down Expand Up @@ -100,7 +101,7 @@ def get_primary_and_pyname_at(
if isinstance(pyobject, pyobjectsdef.PyFunction):
parameter_name = pyobject.get_parameters().get(keyword_name, None)
return (None, parameter_name)
elif isinstance(pyobject, pyobjects.AbstractFunction):
if is_abstract_function(pyobject):
parameter_name = rope.base.pynames.ParameterName()
return (None, parameter_name)
# class body
Expand Down Expand Up @@ -138,11 +139,9 @@ def get_enclosing_function(self, offset):
function_pyname = None
if function_pyname is not None:
pyobject = function_pyname.get_object()
if isinstance(pyobject, pyobjects.AbstractFunction):
if is_abstract_function(pyobject):
return pyobject
elif (
isinstance(pyobject, pyobjects.AbstractClass) and "__init__" in pyobject
):
elif is_abstract_class(pyobject) and "__init__" in pyobject:
return pyobject["__init__"].get_object()
elif "__call__" in pyobject:
return pyobject["__call__"].get_object()
Expand Down Expand Up @@ -186,7 +185,7 @@ def _get_returned(pyobject):
args = arguments.create_arguments(primary, pyobject, node, self.scope)
return pyobject.get_returned_object(args)

if isinstance(pyobject, rope.base.pyobjects.AbstractClass):
if is_abstract_class(pyobject):
result = None
if "__new__" in pyobject:
new_function = pyobject["__new__"].get_object()
Expand All @@ -197,7 +196,7 @@ def _get_returned(pyobject):
return

pyfunction = None
if isinstance(pyobject, rope.base.pyobjects.AbstractFunction):
if is_abstract_function(pyobject):
pyfunction = pyobject
elif "__call__" in pyobject:
pyfunction = pyobject["__call__"].get_object()
Expand Down Expand Up @@ -339,13 +338,12 @@ def _Slice(self, node):

def _call_function(self, node, function_name, other_args=None):
pyname = eval_node(self.scope, node)
if pyname is not None:
pyobject = pyname.get_object()
else:
if pyname is None:
return
pyobject = pyname.get_object()
if function_name in pyobject:
called = pyobject[function_name].get_object()
if not called or not isinstance(called, pyobjects.AbstractFunction):
if not called or not is_abstract_function(called):
return
args = [node]
if other_args:
Expand Down
6 changes: 4 additions & 2 deletions rope/base/oi/soa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import rope.base.oi.soi
import rope.base.pynames
from rope.base import arguments, evaluate, nameanalyze, pyobjects
from rope.base.pyobjects import is_abstract_class, is_abstract_function


def analyze_module(pycore, pymodule, should_analyze, search_subscopes, followed_calls):
Expand Down Expand Up @@ -55,9 +56,10 @@ def _Call(self, node):
if pyname is None:
return
pyfunction = pyname.get_object()
if isinstance(pyfunction, pyobjects.AbstractFunction):
if is_abstract_function(pyfunction):
args = arguments.create_arguments(primary, pyfunction, node, self.scope)
elif isinstance(pyfunction, pyobjects.PyClass):
# elif isinstance(pyfunction, pyobjects.PyClass):
elif is_abstract_class(pyfunction):
pyclass = pyfunction
if "__init__" in pyfunction:
pyfunction = pyfunction["__init__"].get_object()
Expand Down
3 changes: 2 additions & 1 deletion rope/base/oi/soi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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
from rope.base.pyobjects import is_abstract_function

_ignore_inferred = utils.ignore_exception(pyobjects.IsBeingInferredError)

Expand Down Expand Up @@ -201,7 +202,7 @@ 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, pyobjects.AbstractFunction):
if is_abstract_function(pyobject):
args = arguments.ObjectArguments([pyname])
pyobject = pyobject.get_returned_object(args)
else:
Expand Down
3 changes: 2 additions & 1 deletion rope/base/oi/transform.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.
from rope.base import exceptions
from rope.base.pyobjects import is_abstract_class


class PyObjectToTextual:
Expand Down Expand Up @@ -32,7 +33,7 @@ def __call__(self, pyobject):
return self.transform(pyobject)

def PyObject_to_textual(self, pyobject):
if isinstance(pyobject.get_type(), rope.base.pyobjects.AbstractClass):
if is_abstract_class(pyobject.get_type()):
result = self.transform(pyobject.get_type())
if result[0] == "defined":
return ("instance", result)
Expand Down
Loading