E128 как исправить ошибку

I have this statement as a few lines:

    return render_to_response('foo/page.html',
        {
            'situations': situations,
            'active': active_req,
        },
        context_instance=RequestContext(request))

As it stands, using the PEP8 script, it gives me an «E128: continuation line under-indented for visual indent» error on the second line.

I’ve tried a whole bunch of different ways of formatting, and the only way I can get PEP8 to stop complaining is:

    return render_to_response('foo/page.html', {
        'situations': situations,
        'active': active_req,
    },
        context_instance=RequestContext(request))

But this looks like garbage.

Suggestions? E124, E126, and E128 seem to be a huge pain!

I don’t mind solutions which have the { on the first line (or on it’s own), but I hope there’s a solution where the }, and context_instance... are at the same indentation level.

Continuation line under-indented for visual indent

A continuation line is under-indented for a visual indentation.

Anti-pattern

In this example the string "World" is under-indented by two spaces.

print("Python", ("Hello",
               "World"))

Best practice

print("Python", ("Hello",
                 "World"))

I have a python script and flake8 detected some errors for my script:

231 flake8  
E128 continuation line under-indented for visual indent

232 flake8  
E128 continuation line under-indented for visual indent

234 flake8  
E128 continuation line under-indented for visual indent

235 flake8  
E122 continuation line missing indentation or outdented

236 flake8  
E122 continuation line missing indentation or outdented

Here is my code:

t = someFunction (
        data, title=so, Rows=1,
        Widths=[1.2 * inch, 0.3 * inch,
        0.1 * inch, 0.3 * inch, 2 * inch, 3 * inch,
        5.00 * inch],
        style=[("sth1", (0, 0), (-1, -1), "CENTER"),
            ("sth2", (0, 0), (-1, -1), "CENTER"),
            ('sth3', (0, 0), (-1, -1), 0.5, colors.grey),
            ('sth4', (0, 0), (-1, 0), colors.orange),
            ('sth5', (0, 1), (0, -1), colors.orange),
        ])

I tried different permutations, and none work. Could anyone tell me how to format this function?

У меня есть скрипт на python, и flake8 обнаружил некоторые ошибки для моего скрипта:

231 flake8  
E128 continuation line under-indented for visual indent

232 flake8  
E128 continuation line under-indented for visual indent

234 flake8  
E128 continuation line under-indented for visual indent

235 flake8  
E122 continuation line missing indentation or outdented

236 flake8  
E122 continuation line missing indentation or outdented

Вот мой код:

t = someFunction (
        data, title=so, Rows=1,
        Widths=[1.2 * inch, 0.3 * inch,
        0.1 * inch, 0.3 * inch, 2 * inch, 3 * inch,
        5.00 * inch],
        style=[("sth1", (0, 0), (-1, -1), "CENTER"),
            ("sth2", (0, 0), (-1, -1), "CENTER"),
            ('sth3', (0, 0), (-1, -1), 0.5, colors.grey),
            ('sth4', (0, 0), (-1, 0), colors.orange),
            ('sth5', (0, 1), (0, -1), colors.orange),
        ])

Я пробовал разные перестановки, и ни одна из них не работала. Может кто-нибудь сказать мне, как отформатировать эту функцию?

1 ответ

Лучший ответ

E122: Когда вы используете строку продолжения для нескольких аргументов функции, они должны использовать обычный отступ в 4 столбца.

E128: Когда вы распределяете элементы списка, dict, tuple и т. Д. По нескольким строкам, вам нужно выровнять их слева.

t = someFunction (
    Widths=[1.2 * inch, 0.3 * inch,
            0.1 * inch, 0.3 * inch, 2 * inch, 3 * inch,
            5.00 * inch],
    style=[("sth1", (0, 0), (-1, -1), "CENTER"),
           ("sth2", (0, 0), (-1, -1), "CENTER"),
           ('sth3', (0, 0), (-1, -1), 0.5, colors.grey),
           ('sth4', (0, 0), (-1, 0), colors.orange),
           ('sth5', (0, 1), (0, -1), colors.orange)]
)

Вот документация:

В строке продолжения отсутствует отступ или отступ (E122)

Строка продолжения с отступом для визуального отступа (E128)


0

Barmar
12 Сен 2019 в 23:43

Permalink

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Go to file

  • Go to file

  • Copy path


  • Copy permalink

Cannot retrieve contributors at this time

code message title links

E128

Continuation line under-indented for visual indent

Continuation line under-indented for visual indent (E128)

https://www.python.org/dev/peps/pep-0008/#indentation

A continuation line is under-indented for a visual indentation.

Anti-pattern

In this example the string "World" is under-indented by two spaces.

print("Python", ("Hello",
               "World"))

Best practice

print("Python", ("Hello",
                 "World"))

Понравилась статья? Поделить с друзьями:
  • Как исправить зрение при близорукости дома
  • Как исправить ошибку видео файла
  • Как найти хорошие кинофильмы
  • Как найти в телефоне удаленные сообщения вайбер
  • Как найти сопровождающего для ребенка в самолете