【发布时间】:2021-05-28 19:23:05
【问题描述】:
用长类型注解设置函数定义样式的规范(基于一些 PEP)方法是什么?
我能想到的一些替代方案:
- 选项 1:
def my_long_function_name_super_important(
first_long_argument_to_my_function: Union[int, str],
second: Dict[int, str],
third_arg: int = 0 ) -> (bool, int):
return (True, 1)
- 选项 2:
def my_long_function_name_super_important(
first_long_argument_to_my_function: Union[int, str],
second: Dict[int, str],
third_arg: int = 0
) -> (bool, int):
return (True, 1)
- 选项 3:
def my_long_function_name_super_important(
first_long_argument_to_my_function: Union[int, str],
second: Dict[int, str], third_arg: int = 0
) -> (bool, int):
return (True, 1)
- 选项 4:
def my_long_function_name_super_important(
first_long_argument_to_my_function: Union[int, str],
second: Dict[int, str],
third_arg: int = 0,
) -> (bool, int):
return (True, 1)
注意:以 Python 3.8+ 为目标以获得最新答案。
【问题讨论】:
-
没有。
black格式化程序似乎已经得到了认真的采用,但它仍然不是官方的,因此是“意见”。 -
你能把它变成一个答案吗?也许显示
black推荐的格式? -
为什么要投反对票?至少发表评论:(我仍然认为这是一个完全有效的问题。否则,请评论它的缺陷
-
要求编码风格可能是固执己见。不应要求基于批准的 PEP 的 canon 编码风格。
标签: python python-3.x python-3.8 type-hinting pep