Question

So I am in need of some type hinting in pydev and have found this : http://pydev.org/manual_adv_type_hints.html

class MyClass:

def method(self, a):
    ':type a: ClassA'

This works as a charm.

However if I have something like this: class MyClass:

def method(self, a, b):
    ':type a: ClassA'

How do I get type hints for both parameters? I have tried all kinds of combinations of

':type a,b: ClassA, ClassB

or

':type a, ClassA'
':type b, ClassB'

or

':type a, ClassA, b, ClassB'

Any suggestions? Or is it even possible?

Was it helpful?

Solution

I've noticed it works with this format:

class MyClass:

    def method(self, a, b):
        #: :type a: ClassA
        #: :type b: ClassB

It's also a bit more readable if you ask me. I've only been doing Python as a hobby for about a week, so don't take my word for it.

Nice thing about this format is that it works in for pretty much all type hinting (examples from PyDev manual):

class MyClass:

    def method(self, lst):
        #Can be on the same line
        for a in lst: #: :type a: GUITest
            a.;

or

class MyClass:

    def method(self, lst):
        #Or on the line before
        #: :type a: GUITest
        for a in lst:
            a.;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top