简体   繁体   中英

Getting auto completion with Eclipse + PyDev for function arguments

I am using Eclipse and PyDev with Iron Python on a Windows XP machine. I have a class definition that takes an object as an argument which is itself an instantiation of another class like this:

myObject1 = MyClass1()
myObject2 = MyClass2(myObject1)

The two class definitions are in different modules, myclass1.py and myclass2.py and I was hoping I could get auto completion to work on myObject1 when it is being used in myclass2. In other words, in the file myclass2.py I might have something like this:

""" myclass2.py """
class MyClass2():
    def __init__(self, myObject1):
        self.myObject1 = myObject1
        self.myObject1.  <============== would like auto code completion here

Is it possible to make this work?

Thanks!

With a spam line ( if False ... ) with creating object, it's OK with my Pydev 2.5.

""" myclass2.py """
    class MyClass2():
    def __init__(self, myObject1):
        if False : myObject1 = MyClass1()
        self.myObject1 = myObject1        
        self.myObject1.  <============== would like auto code completion here

Using Jython in PyDev/Eclipse, I've wondered about this too. Code completion should work for MyClass1 methods you've used somewhere else in MyClass2, but not for the entire API. I think it's because you can add and remove methods from a class on the fly, so Eclipse can't guarantee that any particular method exists, or that a list of methods is complete.

For example:

>>> class a:
...     def b(self):
...         print('b')
...
>>> anA = a()
>>> anA.b()
b
>>> del a.b
>>> anA.b()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: a instance has no attribute 'b'

So if code completion showed you the method b() here, it would be incorrect.

Similarly,

>>> class a:
...     pass
...
>>> anA = a()
>>> anA.b()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: a instance has no attribute 'b'
>>> def b(self):
...     print('b')
...
>>> a.b = b
>>> anA.b()
b

So code completion that didn't show the method b() would be incorrect.

I could be wrong, but I think it's a solid guess. :)

Do you have an __init__.py in your source folder? It can be empty, but it should exist in all folders so that Python knows to read the files contained therein for Classes for the purpose of autocompletion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM