Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 返回键入提示时换行的正确方法是什么_Python_Conventions - Fatal编程技术网

Python 返回键入提示时换行的正确方法是什么

Python 返回键入提示时换行的正确方法是什么,python,conventions,Python,Conventions,假设我有这样的代码: def on_test_end(self,test_dict:dict[str,Union[Tensor,List[str]]): """ 可选覆盖测试输出的后处理 期望测试dict包含“outputs”和“id” """ 返回测试命令 这非常适合建议的大约80个字符的宽度。但当我添加返回类型时: def on_test_end(self,test_dict:dict[str,Union[Tensor,List[str]])->dict[str,Union[Tensor,

假设我有这样的代码:

def on_test_end(self,test_dict:dict[str,Union[Tensor,List[str]]):
"""
可选覆盖测试输出的后处理
期望测试dict包含“outputs”和“id”
"""
返回测试命令
这非常适合建议的大约80个字符的宽度。但当我添加返回类型时:

def on_test_end(self,test_dict:dict[str,Union[Tensor,List[str]])->dict[str,Union[Tensor,List[str]]:
"""
可选覆盖测试输出的后处理
期望测试dict包含“outputs”和“id”
"""
返回测试命令

它不合适。那么换行符应该放在哪里呢?

不是对实际问题的回答,但可能会将
联合[Tensor,List[str]]
或整个
Dict[…]
定义为一个单独的类型?是的,这会使代码看起来更漂亮,但不知何故可读性会降低,因为我需要为其他一些事情这样做,读者将不得不来回阅读reference@AlexanderSoare大多数html文档生成器,如
pdoc
解析别名类型,因此读者不必搜索引用。