python - 如何为多行导入禁用 flake8?

标签 python pyflakes

使用 flake8,要禁用一行中的某个错误,您可以这样做:

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

但是,如果我有多行语句,flake8 会失败最后解析 noqa 语句:

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   

我想使用 '\' 来继续,所以我不想这样做(这确实有效)

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          

这里有什么帮助吗?

最佳答案

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)

您只需要一个 noqa。 Flake8 将续行视为单个行。

关于python - 如何为多行导入禁用 flake8?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46795404/

相关文章:

python - 有没有办法知道 Unicode 字符串是否包含 Python 中的任何中文/日文字符?

python - 了解插槽并在 Alexa Skills Kit 中获取其值

Python 解释器解析正则表达式

python - dask 数据框应用元

python - 如何在 Spyder 编辑器中抑制某个警告?

python - Flake8 不在全局 python 实例中使用 pyflakes

python - Pandas 到PySpark转换器

python - pylint 错误 - 使用@property + @foo.setter 时出现 E1101 和 E0102

python - 在列表项的循环中保持前一项可访问的优雅方法

Python:pyflakes 不解释 noqa 评论