编写python类型注释时处理79个字符的限制

时间:2018-07-13 06:07:49

标签: python pep8 typing

在编写脚本时,我得到了如下所示的函数签名

def do_multiprocess_action(some_argument: str, communication_pipe: typing.Optional[multiprocessing.connection.Connection]) -> subprocess.Popen:

为了遵守PEP8,我将定义如下所示拆分

def do_multiprocess_action(some_argument: str,
                           communication_pipe: typing.Optional[multiprocessing.connection.Connection]
                           ) -> subprocess.Popen:

,但是带有类型注释,该行太长。处理这个的惯用方式是什么?

1 个答案:

答案 0 :(得分:3)

您可以先定义注释,然后编写函数:

MultiprocessingConnection = typing.Optional[
    multiprocessing.connection.Connection]

def do_multiprocess_action(some_argument: str, 
    communication_pipe: MultiprocessingConnection) -> subprocess.Popen: