Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable flake8 for a multiline import?

With flake8, to disable a certain error on a line you do this:

example = lambda: 'example'  # noqa: E731,E123

However, if I have multiline a statement, flake8 fails to parse the noqa statment at the end:

from detect_fixtures import expected_response_stage3_mocked, expected_response_bbox_oob,\
    mock_detection, mock_detection_models, mock_detection_stage1, mock_detection_stage2,\
    mock_detection_stage3_given_bbox, mock_load_image  # noqa: F401   

I want to use '\' for continuation, so I don't want to do this (which does work)

from detect_fixtures import (expected_response_stage3_mocked,  # noqa: F401                      
    expected_response_bbox_oob, img, mock_detection, mock_detection_models,  # noqa: F401        
    mock_detection_stage1, mock_detection_stage2, mock_detection_stage3_given_bbox,  # noqa: F401
    mock_load_image)  # noqa: F401          

Any help here?

like image 487
M.R. Avatar asked Oct 17 '17 16:10

M.R.


People also ask

How do I turn off flake8?

If we ever want to disable Flake8 respecting # noqa comments, we can can refer to flake8 --disable-noqa . Finally, if we have a particularly bad line of code, we can ignore every error using simply # noqa with nothing after it.

How do I ignore E501 in flake8?

[flake8] per-file-ignores = # line too long path/to/file.py: E501, This may be easier than using # noqa comments.

What is flake8?

Flake8 is a Python library that wraps PyFlakes, pycodestyle and Ned Batchelder's McCabe script. It is a great toolkit for checking your code base against coding style (PEP8), programming errors (like “library imported but unused” and “Undefined name”) and to check cyclomatic complexity.


1 Answers

from detect_fixtures import (expected_response_stage3_mocked,  # noqa: F401                      
    expected_response_bbox_oob, img, mock_detection, mock_detection_models,  
    mock_detection_stage1, mock_detection_stage2, mock_detection_stage3_given_bbox,
    mock_load_image)

You only need one noqa. Flake8 views continuation lines as a single one.

like image 132
YCFlame Avatar answered Sep 21 '22 04:09

YCFlame