What is PEP8's E128: continuation line under-indented for visual indent?

后端 未结 2 624
刺人心
刺人心 2020-12-04 04:56

Just opened a file with Sublime Text (with Sublime Linter) and noticed a PEP8 formatting error that I\'d never seen before. Here\'s the text:

urlpatterns = p         


        
相关标签:
2条回答
  • 2020-12-04 05:26

    This goes also for statements like this (auto-formatted by PyCharm):

        return combine_sample_generators(sample_generators['train']), \
               combine_sample_generators(sample_generators['dev']), \
               combine_sample_generators(sample_generators['test'])
    

    Which will give the same style-warning. In order to get rid of it I had to rewrite it to:

        return \
            combine_sample_generators(sample_generators['train']), \
            combine_sample_generators(sample_generators['dev']), \
            combine_sample_generators(sample_generators['test'])
    
    0 讨论(0)
  • 2020-12-04 05:38

    PEP-8 recommends you indent lines to the opening parentheses if you put anything on the first line, so it should either be indenting to the opening bracket:

    urlpatterns = patterns('',
                           url(r'^$', listing, name='investment-listing'))
    

    or not putting any arguments on the starting line, then indenting to a uniform level:

    urlpatterns = patterns(
        '',
        url(r'^$', listing, name='investment-listing'),
    )
    
    urlpatterns = patterns(
        '', url(r'^$', listing, name='investment-listing'))
    

    I suggest taking a read through PEP-8 - you can skim through a lot of it, and it's pretty easy to understand, unlike some of the more technical PEPs.

    0 讨论(0)
提交回复
热议问题