Code completion - yet another question

Hi there,

Lets assume we have:
class A:
    def __init__(self):
        self.var = 1

l = []
l.append(A())
l.append(A())

l[0].var += 1  # no type hint
prettyPrint();
Is there a way to communicate PyCharm the type of the list items, so that I can take advantage of code completion?

I know I can use the following:
for obj in l:
    assert isinstance(obj, A)
    print obj.var  # type hint works
prettyPrint();
However, I would prefer code completion without using isinstance or list iteration as with the above example.  

Please advice,
Sebi
5 comments
Comment actions Permalink
Add the following comment before the initialization of l:
#: :type l: list of A
prettyPrint();
0
Comment actions Permalink
wow! no wonder I like the looks of this ide; good documentation buys you multi-help.
0
Comment actions Permalink
Is there complete documentation of type hinting somewhere?
0
Comment actions Permalink
Not at the moment.
0
Comment actions Permalink
I didn´t even know that PyCharm infers types from assertions.
Thanks!
0

Please sign in to leave a comment.