Search code examples
pythonpyflakes

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?


Solution

  • 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.