Define functions with too many arguments to abide by PEP8 standard

前端 未结 7 649
日久生厌
日久生厌 2021-02-01 00:12

I have defined a function with a long list of arguments. The total characters in definition is above 80 and doesn\'t abide by PEP8.

def my_function(argument_one,         


        
7条回答
  •  长发绾君心
    2021-02-01 00:58

    For Python code that uses type annotations, I suggest this:

    def some_func(
        foo: str,
        bar: str = 'default_string',
        qux: Optional[str] = None,
        qui: Optional[int] = None,
    ) -> List[str]:
        """
        This is an example function.
        """
        print(foo)
        ...
    

    If you use yapf you can use these options in .style.yapf:

    [style]
    dedent_closing_brackets = true
    split_arguments_when_comma_terminated = true
    

提交回复
热议问题