Search code examples
pythonclassmethodsliclipse

Best practice for using argument's class method


I am trying to figure out the solution for the following problem:

#ExampleA.py
class a:
    def my_great_method_A(self):
        pass

#ExampleB.py
def functionX(inst_a): #Argument 'inst_a' will be always ExampleA.py's class a.
    inst_a.my_great_method_A() #<--- 

I use Liclipse as a python editor. When I am typing the last line, "a.my_gr...", I want to have the editor's auto filling feature kicks in to suggest to use "my_great_method_A()". However, it actually does not suggest anything.

I understand why, because the editor doesn't have any clue if 'inst_a' is class 'a'. To deal with this issue, I could do the following to make the autofiller work:

#ExampleA.py
class a:
    def my_great_method_A(self):
        pass

#ExampleB.py
import ExampleA

def functionX(inst_a): #Argument 'inst_a' will be always ExampleA.py's class a.
    ExampleA.a.my_great_method_A(inst_a) #<--- then autofilling works

However, for the code's readability, I would rather use the . format and I believe everyone the same way. But I do not know how everyone deals with this. Many times I have to go into the imported file and copy & paste the method name, which is tedious. Obviously I am missing something that everyone is aware of. By the way this is my first time to post on stackoverflow. I hope this is a valid thing to pose here.


Solution

  • LiClipse/PyDev can recognize type hints in docstrings (as explained in http://www.pydev.org/manual_adv_type_hints.html) or using the new PEP 484 type hints (https://www.python.org/dev/peps/pep-0484/)... So, if you use one of those, it should work.

    Note: I personally like docstrings better, but it's probably a matter of taste and both should be recognizable by LiClipse/PyDev.