为nbdev提供更好文档的实用扩展
项目描述
详尽的nbdev (nbverbose)
nbdev的附加组件,允许显式参数文档
安装
pip install nbverbose
如何使用
此库作为nbdev的show_doc功能的就地替换,并扩展它以允许对输入进行文档记录。它还建立在fastcore内部的docments功能之上:[文档](https://fastcore.fast.ai/docments)
除了nbdev之外的所有内容都运行正常,您应使用正常的nbdev约定,但是您应该使用from nbverbose.showdoc import *而不是from nbdev.showdoc import *。
下面是一个示例,说明将会发生什么
首先,我们导入库
from nbverbose.showdoc import *
The history saving thread hit an unexpected error (DatabaseError('database disk image is malformed')).History will not be written to the database.
接下来,我们将编写一个非常基础的函数,它有新的方式来记录输入。
不需要有非常长的文档字符串,您的代码可以遵循以下声明格式。空格等不是必需的,只需每个参数必须在新的行上
def addition(
    a:int, # The first number to be added
    b:(int, float)=2, # The second number to be added
):
    "Adds two numbers together"
    return a+b
如你所见,文档格式是name后跟type(如正常),但在单行注释之后,你可以为它添加一个简短的关联文档字符串。
当你调用show_doc或doc函数,围绕addition时,它会看起来像这样
addition[source]
addition(a:int,b:(<class 'int'>, <class 'float'>)=2)
将两个数字相加
参数
- 
a:<class 'int'>要相加的第一个数字 
- 
b:(<class 'int'>, <class 'float'>), 可选要相加的第二个数字 
我们可以看到我们的类型格式正确。这甚至适用于 Union 或 List 的情况
from typing import Union
def addition(
    a:int, # The first number to be added
    b:Union[int, float]=2., # The second number to be added
):
    "Adds two numbers together"
    return a+b
addition[源代码]
addition(a:int,b:Union[int,float]=2.0)
将两个数字相加
参数
- 
a:<class 'int'>要相加的第一个数字 
- 
b:typing.Union[int, float], 可选要相加的第二个数字 
任何通常不遵循此格式的函数仍然可以正常工作
def addition(
    a:int,
    b:Union[int, float],
):
    "Adds two numbers together"
    return a+b
addition[source]
addition(a:int,b:Union[int,float])
将两个数字相加
参数
- 
a:<class 'int'>
- 
b:typing.Union[int, float]
def addition(a:int,b:Union[int, float]):
    "Adds two numbers together"
    return a+b
addition[source]
addition(a:int,b:Union[int,float])
将两个数字相加
参数
- 
a:<class 'int'>
- 
b:typing.Union[int, float]
{% include note.html content='这些示例中的 [源代码] 按钮不会指向现有内容。这是由于 addition 不是我们库的一部分。这将在你使用 nbdev-构建的库中正常工作。' %}
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定要选择哪个,请了解更多关于 安装包 的信息。