Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 240
RPG Avatar asked Mar 12 '26 15:03

RPG


2 Answers

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. :)

like image 90
Rob Lourens Avatar answered Mar 15 '26 05:03

Rob Lourens


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
like image 32
jean-marc C. Avatar answered Mar 15 '26 05:03

jean-marc C.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!