【发布时间】:2021-12-23 03:20:48
【问题描述】:
我正在尝试使用joke2k/faker 来生成假数据。允许使用函数名称动态生成,例如"random_int",我用
inspect 查找函数的签名。签名应包括输入参数的数据类型和默认值。
inspect.signature(fake.random_int)
但它返回以下没有数据类型:
<Signature (min=0, max=9999, step=1)>
我在 faker 库中检查 source code of the function,inspect 应该返回 <Signature (min: int = 0, max: int = 9999, step: int = 1) -> int>。
def random_int(self, min: int = 0, max: int = 9999, step: int = 1) -> int:
"""Generate a random integer between two integers ``min`` and ``max`` inclusive
while observing the provided ``step`` value.
This method is functionally equivalent to randomly sampling an integer
from the sequence ``range(min, max + 1, step)``.
:sample:
:sample size=10: min=0, max=15
:sample size=10: min=0, max=15, step=3
"""
return self.generator.random.randrange(min, max + 1, step)
代码编译到 python 库时,python 类型会丢失吗?如何重新编译保留打字的库?
【问题讨论】:
标签: python-3.x faker