简体   繁体   中英

Sphinx docstring: specify class type instead of object?

In Sphinx, say that you had a function that takes one parameter. Your docstring might look like the following:

class A(object):
    pass

def funct1(a_object):
    """
    :type a_object: A
    """
    pass

funct1(A())

However, what if you aren't passing an object of class A, but rather the class "A" itself? How would that docstring look?

class B(object):
    pass

def funct2(b_class):
    """
    :type b_class: ?????
    """
    pass

funct2(B)

I think that this should work for type hinting, even if it isn't 100% technically accurate:

class B(object):
    pass

def funct2(b_class):
    """
    :type b_class: () -> B
    """
    pass

funct2(B)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM