当一个函数接受类型注释作为参数时,你会使用哪种类型的注释?
为什么我要将类型注释作为参数?
我有一个函数,它尝试根据类型注释解析字符串。
例如:
为什么我要将类型注释作为参数?
我有一个函数,它尝试根据类型注释解析字符串。
例如:
def get_appropriate_type_converter(type_annotation) -> Callable[[str], 'type_annotation']:
e.g.
get_appropriate_type_converter(Dict[str, int])("aaa:3,bbb:4") == dict(aaa=3, bbb=4)
我希望对这个函数进行类型注释。
get_appropriate_type_converter
函数的实现示例吗? - a_guest返回 str2bool 如果类型注释是整型、浮点型或字符串型: 返回类型注释本身 如果类型注释是 IntEnum 的子类: 返回整型```
- Peter