コード例 #1
0
ファイル: plumbing.py プロジェクト: v1k45/drf-spectacular
def get_doc(obj):
    """ get doc string with fallback on obj's base classes (ignoring DRF documentation). """
    if not inspect.isclass(obj):
        return inspect.getdoc(obj) or ''

    def safe_index(lst, item):
        try:
            return lst.index(item)
        except ValueError:
            return float("inf")

    lib_barrier = min(
        safe_index(obj.__mro__, c)
        for c in spectacular_settings.GET_LIB_DOC_EXCLUDES())
    for cls in obj.__mro__[:lib_barrier]:
        if cls.__doc__:
            return inspect.cleandoc(cls.__doc__)
    return ''
コード例 #2
0
def get_doc(obj):
    """ get doc string with fallback on obj's base classes (ignoring DRF documentation). """
    if not inspect.isclass(obj):
        return inspect.getdoc(obj) or ''

    def safe_index(lst, item):
        try:
            return lst.index(item)
        except ValueError:
            return float("inf")

    lib_barrier = min(
        safe_index(obj.__mro__, c)
        for c in spectacular_settings.GET_LIB_DOC_EXCLUDES())
    for cls in obj.__mro__[:lib_barrier]:
        if cls.__doc__:
            # dedent and cleanup of trailing white space on each line
            doc = inspect.cleandoc(cls.__doc__)
            doc = '\n'.join(line.rstrip() for line in doc.rstrip().split('\n'))
            return doc
    return ''