From f35a4ae2b69730c47f1e198623fb323d23f69abc Mon Sep 17 00:00:00 2001 From: ChenXin Date: Fri, 13 Mar 2020 23:36:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E6=B2=A1=E6=9C=89=E7=BC=96=E5=86=99?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=96=87=E6=A1=A3=E7=9A=84=E6=83=85=E5=86=B5?= =?UTF-8?q?=E4=B8=8B=E4=B8=8D=E4=BC=9A=E6=8A=A5=E9=94=99=EF=BC=8C=E8=80=8C?= =?UTF-8?q?=E6=98=AF=E6=94=B9=E4=B8=BA=E6=8F=90=E7=A4=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastNLP/core/collect_fn.py | 1 + fastNLP/doc_utils.py | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/fastNLP/core/collect_fn.py b/fastNLP/core/collect_fn.py index 7a869c9a..14add06f 100644 --- a/fastNLP/core/collect_fn.py +++ b/fastNLP/core/collect_fn.py @@ -1,3 +1,4 @@ +"""undocumented""" from builtins import sorted import torch diff --git a/fastNLP/doc_utils.py b/fastNLP/doc_utils.py index d5412ff4..dcf93c12 100644 --- a/fastNLP/doc_utils.py +++ b/fastNLP/doc_utils.py @@ -22,13 +22,17 @@ def doc_process(m): while 1: defined_m = sys.modules[module_name] - if "undocumented" not in defined_m.__doc__ and name in defined_m.__all__: - obj.__doc__ = r"别名 :class:`" + m.__name__ + "." + name + "`" \ - + " :class:`" + module_name + "." + name + "`\n" + obj.__doc__ - break - module_name = ".".join(module_name.split('.')[:-1]) - if module_name == m.__name__: - # print(name, ": not found defined doc.") + try: + if "undocumented" not in defined_m.__doc__ and name in defined_m.__all__: + obj.__doc__ = r"别名 :class:`" + m.__name__ + "." + name + "`" \ + + " :class:`" + module_name + "." + name + "`\n" + obj.__doc__ + break + module_name = ".".join(module_name.split('.')[:-1]) + if module_name == m.__name__: + # print(name, ": not found defined doc.") + break + except: + print("Warning: Module {} lacks `__doc__`".format(module_name)) break # 识别并标注基类,只有基类也在 fastNLP 中定义才显示 @@ -40,7 +44,11 @@ def doc_process(m): module_name, i = "fastNLP", 1 for i in range(len(parts) - 1): defined_m = sys.modules[module_name] - if "undocumented" not in defined_m.__doc__ and name in defined_m.__all__: - obj.__doc__ = r"基类 :class:`" + defined_m.__name__ + "." + base.__name__ + "` \n\n" + obj.__doc__ + try: + if "undocumented" not in defined_m.__doc__ and name in defined_m.__all__: + obj.__doc__ = r"基类 :class:`" + defined_m.__name__ + "." + base.__name__ + "` \n\n" + obj.__doc__ + break + module_name += "." + parts[i + 1] + except: + print("Warning: Module {} lacks `__doc__`".format(module_name)) break - module_name += "." + parts[i + 1]