diff --git a/rope/base/arguments.py b/rope/base/arguments.py index 12a626816..3bfcb8af3 100644 --- a/rope/base/arguments.py +++ b/rope/base/arguments.py @@ -1,5 +1,6 @@ import rope.base.evaluate from rope.base import ast +from rope.base.pyobjects import is_abstract_class class Arguments: @@ -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 diff --git a/rope/base/builtins.py b/rope/base/builtins.py index 151c64742..bbae06219 100644 --- a/rope/base/builtins.py +++ b/rope/base/builtins.py @@ -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 @@ -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 @@ -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 @@ -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)), @@ -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)), @@ -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) @@ -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 @@ -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: @@ -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): diff --git a/rope/base/evaluate.py b/rope/base/evaluate.py index d9bef3cdb..224c8f4e2 100644 --- a/rope/base/evaluate.py +++ b/rope/base/evaluate.py @@ -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 @@ -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 @@ -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() @@ -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() @@ -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() @@ -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: diff --git a/rope/base/oi/soa.py b/rope/base/oi/soa.py index df60c6fbb..3a479b600 100644 --- a/rope/base/oi/soa.py +++ b/rope/base/oi/soa.py @@ -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): @@ -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() diff --git a/rope/base/oi/soi.py b/rope/base/oi/soi.py index 8bdadaa1c..a469281d5 100644 --- a/rope/base/oi/soi.py +++ b/rope/base/oi/soi.py @@ -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) @@ -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: diff --git a/rope/base/oi/transform.py b/rope/base/oi/transform.py index 968e70b25..2d88e9144 100644 --- a/rope/base/oi/transform.py +++ b/rope/base/oi/transform.py @@ -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: @@ -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) diff --git a/rope/base/pyobjects.py b/rope/base/pyobjects.py index bb1226f92..1493bc89a 100644 --- a/rope/base/pyobjects.py +++ b/rope/base/pyobjects.py @@ -1,13 +1,12 @@ from typing import Optional from rope.base import ast, exceptions, utils +import rope.base.builtins class PyObject: def __init__(self, type_): - if type_ is None: - type_ = self - self.type = type_ + self.type = self if type_ is None else type_ def get_attributes(self): if self.type is self: @@ -66,22 +65,36 @@ def __iter__(self): """The same as ``iter(self.get_attributes())``""" return iter(self.get_attributes()) - _types = None - _unknown = None - @staticmethod - def _get_base_type(name): - if PyObject._types is None: - PyObject._types = {} - base_type = PyObject(None) - PyObject._types["Type"] = base_type - PyObject._types["Module"] = PyObject(base_type) - PyObject._types["Function"] = PyObject(base_type) - PyObject._types["Unknown"] = PyObject(base_type) - return PyObject._types[name] +def is_abstract_class(obj): + return isinstance( + obj, + ( + rope.base.builtins.BuiltinClass, + rope.base.builtins.Generator, + rope.base.builtins.Iterator, + PyClass, + ), + ) -def get_base_type(name): +def is_abstract_function(obj): + return isinstance( + obj, (rope.base.builtins.BuiltinFunction, rope.base.builtins.Lambda, PyFunction) + ) + + +def is_abstract_module(obj): + return isinstance( + obj, + (rope.base.builtins.BuiltinModule, _PyModule), + ) + + +_anchor_types = None + + +def get_base_type(name: str) -> PyObject: """Return the base type with name `name`. The base types are 'Type', 'Function', 'Module' and 'Unknown'. It @@ -89,83 +102,45 @@ def get_base_type(name): is discouraged. Use classes defined in this module instead. For example instead of ``pyobject.get_type() == get_base_type('Function')`` use - ``isinstance(pyobject, AbstractFunction)``. + ``is_abstract_function(pyobject)``. - You can use `AbstractClass` for classes, `AbstractFunction` for - functions, and `AbstractModule` for modules. You can also use - `PyFunction` and `PyClass` for testing if an object is - defined somewhere and rope can access its source. These classes - provide more methods. + You can use `is_abstract_class` for classes, `is_abstract_functions` for + functions, and `is_abstract_module` for modules. """ - return PyObject._get_base_type(name) + global _anchor_types + if _anchor_types is None: + base_type = PyObject(None) + _anchor_types = { + "Function": PyObject(base_type), + "Module": PyObject(base_type), + "Type": base_type, # a Class. + "Unknown": PyObject(base_type), + } + return _anchor_types[name] -def get_unknown(): - """Return a pyobject whose type is unknown +def get_unknown() -> PyObject: + """Return a pyobject whose type is unknown. - Note that two unknown objects are equal. So for example you can - write:: + Note that two unknown objects are equal. + + For example you can write:: if pyname.get_object() == get_unknown(): print('cannot determine what this pyname holds') Rope could have used `None` for indicating unknown objects but - we had to check that in many places. So actually this method - returns a null object. - + we had to check that in many places. """ - if PyObject._unknown is None: - PyObject._unknown = PyObject(get_base_type("Unknown")) - return PyObject._unknown - - -class AbstractClass(PyObject): - def __init__(self): - super().__init__(get_base_type("Type")) - - def get_name(self): - pass - - def get_doc(self): - pass - - def get_superclasses(self): - return [] - - -class AbstractFunction(PyObject): - def __init__(self): - super().__init__(get_base_type("Function")) - - def get_name(self): - pass - - def get_doc(self): - pass - - def get_param_names(self, special_args=True): - return [] + return get_base_type("Unknown") - def get_returned_object(self, args): - return get_unknown() - - -class AbstractModule(PyObject): - def __init__(self, doc=None): - super().__init__(get_base_type("Module")) - def get_doc(self): - pass - - def get_resource(self): - pass - - -class PyDefinedObject: +class PyDefinedObject(PyObject): # was: had no base class. """Python defined names that rope can access their sources""" - def __init__(self, pycore, ast_node, parent): + def __init__(self, pycore, ast_node, parent, type_): + super().__init__(type_) self.pycore = pycore self.ast_node = ast_node self.scope = None @@ -264,19 +239,40 @@ def _create_scope(self): pass -class PyFunction(PyDefinedObject, AbstractFunction): - pass +class PyFunction(PyDefinedObject): + # 1. was (PyDefinedObject, AbstractFunction). + # 2. was (PyDefinedObject, PyObject) + + def __init__(self, pycore, ast_node, parent): + super().__init__(pycore, ast_node, parent, get_base_type("Function")) + + # From AbstractFunction. + + def get_param_names(self, special_args=True): + return [] + + def get_returned_object(self, args): + return get_unknown() -class PyComprehension(PyDefinedObject, PyObject): +class PyComprehension(PyDefinedObject): pass def get_name(self): return "" -class PyClass(PyDefinedObject, AbstractClass): - pass +class PyClass(PyDefinedObject): + # 1. Was (PyDefinedObject, AbstractClass). + # 2. Was (PyDefinedObject, PyObject). + + def __init__(self, pycore, ast_node, parent): + super().__init__(pycore, ast_node, parent, get_base_type("Type")) + + # From AbstractClass. + + def get_superclasses(self): + return [] class _ConcludedData: @@ -298,12 +294,16 @@ def __str__(self): return "<" + str(self.data) + ">" -class _PyModule(PyDefinedObject, AbstractModule): +class _PyModule(PyDefinedObject): + """The base class for PyModule and PyPackage.""" + + # 1. was (PyDefinedObject, AbstractModule). + # 2. Was (PyDefinedObject, PyObject). + def __init__(self, pycore, ast_node, resource): self.resource = resource self.concluded_data = [] - AbstractModule.__init__(self) - PyDefinedObject.__init__(self, pycore, ast_node, None) + super().__init__(pycore, ast_node, None, get_base_type("Module")) @property def absolute_name(self) -> str: diff --git a/rope/base/pyobjectsdef.py b/rope/base/pyobjectsdef.py index 95bd15691..d9d37ee98 100644 --- a/rope/base/pyobjectsdef.py +++ b/rope/base/pyobjectsdef.py @@ -14,12 +14,12 @@ pyobjects, utils, ) +from rope.base.pyobjects import is_abstract_module class PyFunction(pyobjects.PyFunction): def __init__(self, pycore, ast_node, parent): - rope.base.pyobjects.AbstractFunction.__init__(self) - rope.base.pyobjects.PyDefinedObject.__init__(self, pycore, ast_node, parent) + super().__init__(pycore, ast_node, parent) self.arguments = self.ast_node.args self.parameter_pyobjects = pynamesdef._Inferred( self._infer_parameters, self.get_module()._get_concluded_data() @@ -114,8 +114,7 @@ def decorators(self): class PyComprehension(pyobjects.PyComprehension): def __init__(self, pycore, ast_node, parent): self.visitor_class = _ComprehensionVisitor - rope.base.pyobjects.PyObject.__init__(self, type_="Comp") - rope.base.pyobjects.PyDefinedObject.__init__(self, pycore, ast_node, parent) + super().__init__(pycore, ast_node, parent, type_="Comp") def _create_scope(self): return rope.base.pyscopes.ComprehensionScope( @@ -129,8 +128,7 @@ def get_kind(self): class PyClass(pyobjects.PyClass): def __init__(self, pycore, ast_node, parent): self.visitor_class = _ClassVisitor - rope.base.pyobjects.AbstractClass.__init__(self) - rope.base.pyobjects.PyDefinedObject.__init__(self, pycore, ast_node, parent) + super().__init__(pycore, ast_node, parent) self.parent = parent self._superclasses = self.get_module()._get_concluded_data() @@ -230,6 +228,8 @@ def get_name(self): return rope.base.libutils.modname(self.resource) if self.resource else "" +# PyModule = PyDefinedModule # Fails +# PyDefinedModule = PyModule # Passes. class PyPackage(pyobjects.PyPackage): def __init__(self, pycore, resource=None, force_errors=False): self.resource = resource @@ -400,7 +400,7 @@ def _Slice(self, node): class _ScopeVisitor(_ExpressionVisitor): def __init__(self, pycore, owner_object): - _ExpressionVisitor.__init__(self, scope_visitor=self) + super().__init__(scope_visitor=self) self.pycore = pycore self.owner_object = owner_object self.names = {} @@ -554,9 +554,7 @@ def _ImportFrom(self, node): def _is_ignored_import(self, imported_module): if not self.pycore.project.prefs.get("ignore_bad_imports", False): return False - return not isinstance( - imported_module.get_object(), rope.base.pyobjects.AbstractModule - ) + return not is_abstract_module(imported_module.get_object()) def _Global(self, node): module = self.get_module() diff --git a/rope/contrib/codeassist.py b/rope/contrib/codeassist.py index 32547891e..4ea0c61f5 100644 --- a/rope/contrib/codeassist.py +++ b/rope/contrib/codeassist.py @@ -16,6 +16,11 @@ ) from rope.contrib import fixsyntax from rope.refactor import functionutils +from rope.base.pyobjects import ( + is_abstract_class, + is_abstract_function, + is_abstract_module, +) def code_assist( @@ -255,7 +260,7 @@ def parameters(self): pyname = pyname._get_imported_pyname() if isinstance(pyname, pynames.DefinedName): pyobject = pyname.get_object() - if isinstance(pyobject, pyobjects.AbstractFunction): + if is_abstract_function(pyobject): return pyobject.get_param_names() @property @@ -277,9 +282,9 @@ def type(self): pyname, pynames.DefinedName ): pyobject = pyname.get_object() - if isinstance(pyobject, pyobjects.AbstractFunction): + if is_abstract_function(pyobject): return "function" - if isinstance(pyobject, pyobjects.AbstractClass): + if is_abstract_class(pyobject): return "class" return "instance" @@ -515,16 +520,13 @@ def _keyword_parameters(self, pymodule, scope): return {} if function_pyname is not None: pyobject = function_pyname.get_object() - if isinstance(pyobject, pyobjects.AbstractFunction): + if is_abstract_function(pyobject): pass - elif ( - isinstance(pyobject, pyobjects.AbstractClass) - and "__init__" in pyobject - ): + elif is_abstract_class(pyobject) and "__init__" in pyobject: pyobject = pyobject["__init__"].get_object() elif "__call__" in pyobject: pyobject = pyobject["__call__"].get_object() - if isinstance(pyobject, pyobjects.AbstractFunction): + if is_abstract_function(pyobject): param_names = [] param_names.extend(pyobject.get_param_names(special_args=False)) result = {} @@ -590,25 +592,25 @@ def _underline_count(name): class PyDocExtractor: def get_doc(self, pyobject): - if isinstance(pyobject, pyobjects.AbstractFunction): + if is_abstract_function(pyobject): return self._get_function_docstring(pyobject) - elif isinstance(pyobject, pyobjects.AbstractClass): + if is_abstract_class(pyobject): return self._get_class_docstring(pyobject) - elif isinstance(pyobject, pyobjects.AbstractModule): + if is_abstract_module(pyobject): return self._trim_docstring(pyobject.get_doc()) return None def get_calltip(self, pyobject, ignore_unknown=False, remove_self=False): try: - if isinstance(pyobject, pyobjects.AbstractClass): + if is_abstract_class(pyobject): pyobject = pyobject["__init__"].get_object() - if not isinstance(pyobject, pyobjects.AbstractFunction): + if not is_abstract_function(pyobject): pyobject = pyobject["__call__"].get_object() except exceptions.AttributeNotFoundError: return None if ignore_unknown and not isinstance(pyobject, pyobjects.PyFunction): return - if isinstance(pyobject, pyobjects.AbstractFunction): + if is_abstract_function(pyobject): result = self._get_function_signature(pyobject, add_module=True) if remove_self and self._is_method(pyobject): return result.replace("(self)", "()").replace("(self, ", "(") @@ -629,7 +631,7 @@ def _get_class_header(pyclass): if "__init__" in pyclass: init = pyclass["__init__"].get_object() - if isinstance(init, pyobjects.AbstractFunction): + if is_abstract_function(init): doc += "\n\n" + self._get_single_function_docstring(init) return doc @@ -658,7 +660,7 @@ def _get_super_methods(self, pyclass, name): for super_class in pyclass.get_superclasses(): if name in super_class: function = super_class[name].get_object() - if isinstance(function, pyobjects.AbstractFunction): + if is_abstract_function(function): result.append(function) result.extend(self._get_super_methods(super_class, name)) return result @@ -677,7 +679,7 @@ def _get_function_signature(self, pyfunction, add_module=False): def _location(self, pyobject, add_module=False): location = [] parent = pyobject.parent - while parent and not isinstance(parent, pyobjects.AbstractModule): + while parent and not is_abstract_module(parent): location.append(parent.get_name()) location.append(".") parent = parent.parent diff --git a/rope/refactor/rename.py b/rope/refactor/rename.py index cb6348009..23513b4b5 100644 --- a/rope/refactor/rename.py +++ b/rope/refactor/rename.py @@ -12,6 +12,7 @@ ) from rope.base.change import ChangeContents, ChangeSet, MoveResource from rope.refactor import occurrences +from rope.base.pyobjects import is_abstract_module class Rename: @@ -138,7 +139,7 @@ def _is_allowed_to_move(self, resources, resource): return resource in resources def _is_renaming_a_module(self): - return isinstance(self.old_pyname.get_object(), pyobjects.AbstractModule) + return is_abstract_module(self.old_pyname.get_object()) def is_method(self): pyname = self.old_pyname diff --git a/rope/refactor/wildcards.py b/rope/refactor/wildcards.py index 13edab91c..5cd9debee 100644 --- a/rope/refactor/wildcards.py +++ b/rope/refactor/wildcards.py @@ -1,5 +1,6 @@ -from rope.base import ast, builtins, evaluate, pyobjects +from rope.base import ast, builtins, evaluate from rope.refactor import occurrences, patchedast +from rope.base.pyobjects import is_abstract_class class Wildcard: @@ -117,7 +118,7 @@ def __call__(self, pymodule, node): def _get_super_classes(self, pyobject): result = [] - if isinstance(pyobject, pyobjects.AbstractClass): + if is_abstract_class(pyobject): for superclass in pyobject.get_superclasses(): result.append(superclass) result.extend(self._get_super_classes(superclass)) diff --git a/ropetest/advanced_oi_test.py b/ropetest/advanced_oi_test.py index 79f514ad0..817ca9bad 100644 --- a/ropetest/advanced_oi_test.py +++ b/ropetest/advanced_oi_test.py @@ -38,9 +38,14 @@ def a_func(arg): return eval("arg") a_var = a_func(mod1) """) + # breakpoint() mod2.write(code) self.pycore.run_module(mod2).wait_process() pymod2 = self.project.get_pymodule(mod2) + if 1: # trace + print('') + print('test_module_dti:', self.project.get_pymodule(mod1).__class__.__name__) + print('test_module_dti:', pymod2["a_var"].get_object().__class__.__name__) self.assertEqual(self.project.get_pymodule(mod1), pymod2["a_var"].get_object()) def test_class_from_another_module_dti(self): diff --git a/ropetest/pycoretest.py b/ropetest/pycoretest.py index 5ccd80d2a..9ab795430 100644 --- a/ropetest/pycoretest.py +++ b/ropetest/pycoretest.py @@ -6,7 +6,7 @@ from rope.base.builtins import BuiltinClass, File from rope.base.pycore import _TextChangeDetector from rope.base.pynamesdef import AssignedName -from rope.base.pyobjects import AbstractFunction, get_base_type +from rope.base.pyobjects import get_base_type from ropetest import testutils @@ -120,11 +120,12 @@ def __init__(self): def f(): pass """) + from rope.base.pyobjects import is_abstract_function mod.write(code) mod_element = self.project.get_module("mod") sample_class = mod_element["C"].get_object() f = sample_class["f"].get_object() - self.assertTrue(isinstance(f, AbstractFunction)) + self.assertTrue(is_abstract_function(f)) def test_classes_inside_other_classes(self): mod = testutils.create_module(self.project, "mod")