Complex type specification in documentation.

Hi, could you please describe how I can specify complex types in doc strings. For instance I found that I could write following for:

class C:

     @classmethod

     def c(cls):

          pass

     def m(self):

          pass

var1 = None

"""

:type : list of C

"""

var1[0]. #<-complete here with members of C

var2 = None

"""

:type : dict from string to C

"""

var2["a"]. #<-complete here with members of C

But the same doesnt work for set or deque.

Also i dont know how to write someting like this:

def f():

     """

     :rtype : iterable of C

     """

     for i in xrange(10):

          yield C()

to have autocomleation in loops:

for g in f()

     g. #<-complete here with members of C

Also i dont know how to specify following:

var3 = None

"""

:type : tuple of int, string, list of C

"""

var3[0]. #<-compleate here with members of int

var3[1]. #<-compleate here with members of string

var3[2]. #<-compleate here with members of list

var3[2][0] #<-compleate here with members of C

Also i want to know how to describe class type:

var4 = None

"""

:type : class of C

"""

var4. #<-compleate here with members of C.__class__

var4.c() #No warn here

var4.m() #<-Warn here for missing argument

var4.m(var1[0]) #No warn here

var4(). #<-compleate here with members of C

thanks in advance.

1 comment
Comment actions Permalink

Hi Alexander,

Currently PyCharm supports only parametrized list and dict bulitin types. Support for other parametrized types may appear in future PyCharm versions. Fill free to post feature requests or vote for existing requests in our issue tracker.

For tuple types use the following syntax:

def f(x):

    '''

    :type x: int

    :rtype: (int, str)

    '''

    return x, str(x)

x, y = f(2)

y.<caret> # suggests encode(), upper(), etc.

0

Please sign in to leave a comment.