Fwd: [Eric] Why does Rope sometimes not find a definition?

Ali Gholami Rudi aliqrudi at gmail.com
Fri Oct 31 11:41:27 GMT 2008


Hi Detlev and OldGrantonian,

On Oct 31 2008 14:07 +0330, Detlev Offenbach wrote:
> The Rope plugin finds the vast majority of definitions. Sometimes a
> definition is not found, and I'm trying to understand why. Please remember
> that I'm not a Python expert.
>
> Here are some lines from a file:
>
> . . . from mnemosyne.pyqt_ui.plugin import *
> . . . main_widget = get_main_widget()
> ...
> . . . main_widget.helpMenu.insertItem("Hello there", hi)
>
>
> Why does Rope find definitions in "plugin.py", but not in "main_frm.py"?

Well... rope usually analyzes the source code statically.
mnemosyne.pyqt_ui.plugin module contains:

  import qt

  def get_main_widget():

      import mnemosyne.pyqt_ui.main_dlg

      for w in qt.qApp.topLevelWidgets():
          if type(w) == mnemosyne.pyqt_ui.main_dlg.MainDlg:
              return w

In order to find out the return value of get_main_widget(), rope needs
to know the object w holds.  Here, rope cannot infer the type of w;
the reason might be the source code of qt.qApp.topLevelWidget() is
unavailable (is this a c-extension module?) or it might use lots of
dynamic behavior.

There is also DOA (dynamic object analysis) which collects object data
when running a module.  But it is slow and probably won't work if
qt.qApp.topLevelWidgets() is not a python function.

Sometimes it might help to increase soa_followed_calls variable (if
the functions are in python).  For instance here is a simplified
version of your situation:

  class A(object):

      def __init__(self):
          self.list = []

      def add(self, o):
          self.list.append(o)

      def get(self):
          return self.list.pop()

  class B(object):

      def b(self):
          pass

  a = A()
  a.add(B())
  b = a.get()

Here if soa_followed_calls is bigger than 1, it can easily infer the
type of b (after performing SOA on the buffer; it is usually
automatically performed by the IDE on the changed scope).  Rope can
infer the type of b even if soa_followed_calls variable is 0, but then
SOA has to be performed twice on this module.

Note that SOA is needed only when rope needs to guess the object based
on how functions are used.  Its main task is to search for function
calls (like a.add(B()) or self.list.append(o)) and obtain more
information about parameters; with this new data rope can update the
return value or find the objects other functions' parameters hold.

Hope this helps :-)

Regards,
Ali


More information about the Eric mailing list