Line is too long. Django PEP8

前端 未结 6 1034
余生分开走
余生分开走 2021-02-01 04:09

PEP8 info:

models.py:10:80: E501 line too long (83 > 79 characters)

Models.py:

field = TreeForeignKey(\'self\', null         


        
6条回答
  •  渐次进展
    2021-02-01 04:48

    I usually split that to line up the parameters one level of indentation deeper than the original line, like:

    field = TreeForeignKey('self', null=True,
        blank=True, related_name='abcdefgh')
    

    Especially if TreeForeignKey is something like TreeForeignKeyWithReferencesToSomethingElse, in which case all the parameters would start out to the far right of the window if you lined them all up with the opening parenthesis. If any of the parameters had a long name like defaultvalueforcertaincircumstances, you might not be able to fit the whole thing in under 80 columns:

    field = TreeForeignKeyWithReferencesToSomethingElse('self',
                                                        defaultvalueforcertaincircumstances='foo')
    

    I also prefer to put multiple function parameters on the same line (except when it just doesn't look right; I'm not a purist!) so that vertical space isn't overly expanded, causing me to spend more time scrolling around in my editor than otherwise necessary.

提交回复
热议问题