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

Ali Gholami Rudi aligrudi at gmail.com
Sat Nov 1 15:31:34 GMT 2008


Hi,

On Sat, Nov 01, 2008 at 11:59:58AM +0000, OldGrantonian wrote:
> Thanks for your very detailed explanation.
> 
> BTW: Because I'm not a programmer, I need a good IDE to browse around other
> people's code. I learn faster that way. I'm simultaneously trying Komodo and
> Wing, and comparing identical searches in the same python project. At the
> moment, I'm only interested in the "browsing" functionality, such as finding
> definitions, finding occurrences, and so on. Eric is vastly superior to the
> other two IDEs. (And Komodo would charge £150 for the "Pro" version, which
> is the only version that has object browsing.)

:-)

> >> On Fri, Oct 31, 2008 at 11:41 AM, Ali Gholami Rudi <aliqrudi at gmail.com>
> wrote:
> 
>     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?)
> 
> 
> Yes, topLevelWidget() is in C-code, which is in SIP files. So, it looks as
> if the simple answer to my question is: Rope cannot find definitions if (a)
> there is too much dynamic behavior, or (b) if the definitions are not
> contained within a ".py" file. Is that true?

With SOA (static object analysis) yes.  DOA (dynamic object analysis), on
the other hand, works in dynamic situations.  For instance:

  class C(object):
	pass
  
  def create_c():
	return eval("C()")

  c = create_c()

DOA can find out the object c holds.  It actually collects the
parameters and the return value of functions after they are called.  So
it doesn't matter how the function is implemented.

DOA should be enabled when executing modules and that makes them
slow (to tell you the truth, because of it I rarely use it ;-) ).

> --------------------------------------------------------
> 
> I have some more questions. If you want me to split these questions into
> separate posts, please let me know.

However you prefer :-)

> If I cannot find a definition because of behaviour that I have just
> discussed, it would still be useful to be able to do a "manual" query using
> "Find Occurrences". It seems that "Find Occurrences" only works within
> Python files. So I need to use an external text-search tool to find some
> occurrences of "get_main_widget" (see above), because this occurs in SIP
> files as well as PY files.
> 
> Maybe "Find Occurrences" could be based on a user-configurable option: "Do
> you want to search in non-Python files?"

Currently rope uses only its object data for matching names.  But other
approaches are possible, too:

* guessing the type based on attributes (see "taking a look at pysmell"
  thread in rope-dev)
* guessing the type based on the name itself (unsure option of rename
  refactoring is an example of this)

These approaches work good when there aren't many similar names in a
project.

Support for searching C files (or other textual files) can be easily
added (if someone volunteers ;-) ).

> If I use "Find Occurrences" to search for get_main_widget, there are 11
> occurrences. (This agrees with my external text-search tool.)
> 
> However, if I use "Find Occurrences" to search for get_main_widget from
> within the file where it is defined, I get the message: "No occurrences
> found."

Find occurrences searches all of the files in a project.  So searching
for a built-in variable or a name in a file outside the project should
find all of the occurrences in the current project.  If it doesn't, it
is probably a bug...

> I have never succeeded in getting "Find Implementations" to work. I
> sometimes get the message: "Rope error: Not a method!", and sometimes: "Rope
> error: String out of range.", and sometimes: "Rope error: Not a resolvable
> Python identifier selected.", and sometimes: "Rope error: Cannot resolve the
> identifier." (For a specific definition, the message is always the same.)
> 
> Here is what I do:
> 
> Highlight the name of the method in the following example:
> 
> def get_main_widget():
> 
> So I would highlight "get_main_widget"
> 
> Then Refactoring > Query > Find Implementations

Find implementations searches for the implementations of a method of a
class.  For instance:

  class A(object):
	def f(self):
		pass

  class B(A):
  	def f(self):
		pass

Performing find implementations on A.f() would find B.f().

> Before using any of the Rope searches, I need to highlight text. If the file
> was never edited, this highlighting causes a random message to "save or
> discard changes" before performing the search.
> 
> I say "random" because the message occurs before at least 50% of the
> searches, but I cannot figure out in advance when the message will appear
> and when it will not appear.

Seems to be eric-related, Detlev?

Regards,
Ali


More information about the Eric mailing list