python-rope / rope

a python refactoring library
GNU Lesser General Public License v3.0
1.96k stars 164 forks source link

AttributeError: 'NoneType' object has no attribute 'parent' in get_calltip #82

Closed jorgenschaefer closed 9 years ago

jorgenschaefer commented 10 years ago

The following code generates an AttributeError. I would expect Rope to simply not return any call tips.

import shutil
import tempfile

import rope.base.project
import rope.contrib.codeassist

project_root = tempfile.mkdtemp()
try:

    project = rope.base.project.Project(project_root)
    rope.contrib.codeassist.get_calltip(
        project, """\                                                           
from .. import foo                                                              
        """, 18
    )

finally:
    shutil.rmtree(project_root)

Backtrace:

Traceback (most recent call last):
  File "foo.py", line 15, in <module>
    """, 18
  File "/home/forcer/.virtualenvs/elpy/local/lib/python2.7/site-packages/rope/contrib/codeassist.py", line 95, in get_calltip
    pyobject = pyname.get_object()
  File "/home/forcer/.virtualenvs/elpy/local/lib/python2.7/site-packages/rope/base/utils.py", line 28, in newfunc
    return func(self, *args, **kwds)
  File "/home/forcer/.virtualenvs/elpy/local/lib/python2.7/site-packages/rope/base/pynames.py", line 159, in get_object
    return self._get_imported_pyname().get_object()
  File "/home/forcer/.virtualenvs/elpy/local/lib/python2.7/site-packages/rope/base/pynames.py", line 150, in _get_imported_pyname
    result = self.imported_module.get_object()[self.imported_name]
  File "/home/forcer/.virtualenvs/elpy/local/lib/python2.7/site-packages/rope/base/pynames.py", line 131, in get_object
    if self._get_pymodule() is None:
  File "/home/forcer/.virtualenvs/elpy/local/lib/python2.7/site-packages/rope/base/pynames.py", line 124, in _get_pymodule
    self.level)
  File "/home/forcer/.virtualenvs/elpy/local/lib/python2.7/site-packages/rope/base/pycore.py", line 101, in get_relative_module
    module = self.find_relative_module(name, folder, level)
  File "/home/forcer/.virtualenvs/elpy/local/lib/python2.7/site-packages/rope/base/pycore.py", line 161, in find_relative_module
    folder = folder.parent
AttributeError: 'NoneType' object has no attribute 'parent'
mcepl commented 9 years ago

Closing as duplicate of #81 and the other one. Please, keep the conversation there.