我正在尝试使用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类型会丢失吗?我如何重新编译保留类型的库?
发布于 2021-11-10 14:32:47
上述情况发生在Faker == 8.16.0上。将Faker升级到版本9.8后,inspect.signature()返回正确的输入。
https://stackoverflow.com/questions/69914753
复制相似问题