能够应用 inspect 模块的 signature 办法来实现
示例代码如下:
from typing import Union
from types import UnionType
from inspect import signature
from loguru import logger
def get_score(name: str | None = None) -> float | None:
pass
typed_signature = signature(get_score).parameters.items()
for index, (parameter_name, parameter) in enumerate(typed_signature):
logger.debug(parameter.default)
输入
2022-10-04 18:59:53.893 | DEBUG | __main__:<module>:15 - None