Pep 8 e701 multiple statements on one line colon как исправить

I'm using flake8 in Visual Studio Code, writing some code using Python 3.6 variable annotations. It worked without any problems so far, but I encountered a strange warning. This works fine: style...

I’m using flake8 in Visual Studio Code, writing some code using Python 3.6 variable annotations. It worked without any problems so far, but I encountered a strange warning.

This works fine:

style: str = """
width: 100%;
...
"""
# Doing sth with `style`

This too:

img_style: str = """
width: 100%;
...
"""
# Doing sth with `img_style`

This however does not, it yields below warning:

iframe_style: str = """
width: 100%;
...
"""
# Doing sth with `iframe_style`

flake8 warning

Well, technically it does work fine; the code runs. But somehow flake8 is not happy with this.
The multiline string and the code following is always the same.

When I omit the «f» (i_rame_style), I don’t get a warning, too! So I guess for some reason flake8 thinks of a if foo: bar() here!?

What am I missing here? Is this a bug in flake8?

asked Apr 11, 2018 at 11:50

linusg's user avatar

linusglinusg

6,1834 gold badges29 silver badges74 bronze badges

6

Edit: The problem is in pycodestyle (pep8), which is called by flake8. The rest still stands.

Second edit: I’ve made some more research and the issue is fixed here. The fix hasn’t been released yet, though.

Definitely looks like a flake8 bug to me:

flakebug.py:

innocuous: str = ""
ifstarting_string: str = ""
forfalse_positivetoo: str = ""
whilethis_lookslikeabug: str = ""
elsehaha: str = ""

In the shell:

$ # python3.6 -m pycodestyle flakebug.py gives the same results
$ python3.6 -m flake8 flakebug.py 
flakebug.py:2:18: E701 multiple statements on one line (colon)
flakebug.py:3:21: E701 multiple statements on one line (colon)
flakebug.py:4:24: E701 multiple statements on one line (colon)
flakebug.py:5:9: E701 multiple statements on one line (colon)

Looks like every line starting with a control flow statement triggers it.
I’d wager it uses a regex like (if|else|while|for).*:.

I’ll try to get to the bottom of this and update this answer if I can, meanwhile you could add some # noqa annotations and you’ll be set :)

answered Apr 11, 2018 at 12:07

etene's user avatar

eteneetene

7004 silver badges12 bronze badges

4

Comments

@futursolo

eddie-dunn

pushed a commit
to eddie-dunn/pycodestyle
that referenced
this issue

Jun 9, 2017

If a Python 3 class variable begins with an indent keyword, i.e.,

class Class:
    with_foo: int

pycodestyle will erroneously output the error 'E701 multiple statements
on one line'. This patch tightens the check so that even variables
beginning with indent keywords are allowed.

Resolves PyCQA#635

LefterisJP

added a commit
to LefterisJP/raiden
that referenced
this issue

Aug 9, 2018

@LefterisJP

LefterisJP

added a commit
to LefterisJP/raiden
that referenced
this issue

Aug 9, 2018

@LefterisJP

LefterisJP

added a commit
to raiden-network/raiden
that referenced
this issue

Aug 10, 2018

@LefterisJP

calin-iorgulescu

added a commit
to calin-iorgulescu/hangups
that referenced
this issue

Nov 22, 2018

@calin-iorgulescu

calin-iorgulescu

added a commit
to calin-iorgulescu/hangups
that referenced
this issue

Nov 22, 2018

@calin-iorgulescu

calin-iorgulescu

added a commit
to calin-iorgulescu/hangups
that referenced
this issue

Nov 22, 2018

@calin-iorgulescu

LefterisJP

added a commit
to LefterisJP/raiden
that referenced
this issue

Feb 7, 2019

@LefterisJP

With a new version of flake8 we can now stop ignoring E701 that was
introduced to this bug: PyCQA/pycodestyle#635

LefterisJP

added a commit
to raiden-network/raiden
that referenced
this issue

Feb 7, 2019

@LefterisJP

With a new version of flake8 we can now stop ignoring E701 that was
introduced to this bug: PyCQA/pycodestyle#635

hackaugusto

pushed a commit
to hackaugusto/raiden
that referenced
this issue

Feb 21, 2019

@LefterisJP

@hackaugusto

With a new version of flake8 we can now stop ignoring E701 that was
introduced to this bug: PyCQA/pycodestyle#635

Я использую flake8 в Visual Studio Code, пишу код с помощью Аннотации переменных Python 3.6. Пока все работало без проблем, но я столкнулся со странным предупреждением.

Это отлично работает:

style: str = """
width: 100%;
...
"""
# Doing sth with `style`

Это тоже:

img_style: str = """
width: 100%;
...
"""
# Doing sth with `img_style`

Однако это не так, это приводит к предупреждению ниже:

iframe_style: str = """
width: 100%;
...
"""
# Doing sth with `iframe_style`

flake8 warning

Что ж, технически это работает нормально; код работает. Но почему-то flake8 это не устраивает. Многострочная строка и следующий за ней код всегда одинаковы.

Когда я опускаю букву «f» (i_rame_style), я тоже не получаю предупреждения! Так что, я думаю, по какой-то причине flake8 думает о if foo: bar() здесь !?

Что мне здесь не хватает? Это ошибка в flake8?

1 ответ

Лучший ответ

Изменить: проблема в pycodestyle (pep8), который вызывается flake8. Остальные по-прежнему в силе.

Второе изменение: я провел дополнительное исследование, и проблема исправлена ​​здесь. Однако исправление еще не выпущено.

Для меня это определенно похоже на ошибку flake8:

flakebug.py:

innocuous: str = ""
ifstarting_string: str = ""
forfalse_positivetoo: str = ""
whilethis_lookslikeabug: str = ""
elsehaha: str = ""

В оболочке:

$ # python3.6 -m pycodestyle flakebug.py gives the same results
$ python3.6 -m flake8 flakebug.py 
flakebug.py:2:18: E701 multiple statements on one line (colon)
flakebug.py:3:21: E701 multiple statements on one line (colon)
flakebug.py:4:24: E701 multiple statements on one line (colon)
flakebug.py:5:9: E701 multiple statements on one line (colon)

Похоже, что каждая строка, начинающаяся с оператора потока управления, запускает его. Держу пари, что здесь используется регулярное выражение вроде (if|else|while|for).*:.

Я постараюсь разобраться в этом и обновить этот ответ, если смогу, а пока вы можете добавить несколько аннотаций # noqa, и все будет готово :)


10

etene
11 Апр 2018 в 15:26

Понравилась статья? Поделить с друзьями:

Читайте также:

  • People playground как изменить размер предмета
  • People playground runtime error
  • Pentahosystem error 0014
  • Pension error notification сзв м
  • Pending data load error teso

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии