当我使用flake8时,如何解决由下划线引起的未使用错误

时间:2019-03-08 04:49:27

标签: flake8

在VSCode中 flake8忽略_未使用的错误 就是这样

try:
   pass
except Exception as _:
   pass

然后flake8显示未使用的错误'_'

1 个答案:

答案 0 :(得分:-2)

  1. 删除/ lib / site-packages / flake8 / __ pycache__ floder
  2. 编辑/Lib/site-packages/flake8/plugins/pyflakes.py运行功能
  3. 重新打开您的py文件,对其进行编辑并保存
    • 修改前
    def run(self):
        """Run the plugin."""
        for message in self.messages:
            col = getattr(message, "col", 0)
            yield (
                message.lineno,
                col,
                "{} {}".format(
                    FLAKE8_PYFLAKES_CODES.get(type(message).__name__, "F999"),
                    message.message % message.message_args,
                ),
                message.__class__,
            )

  • 修改后
    def run(self):
        """Run the plugin."""
        for message in self.messages:
            col = getattr(message, "col", 0)
            if ('F841' in FLAKE8_PYFLAKES_CODES.get(
                    type(message).__name__, "F999")
                    and "'_'" in message.message_args):
                yield (
                    message.lineno,
                    col,
                    "{} {}".format(
                        FLAKE8_PYFLAKES_CODES.get(
                            type(message).__name__, "F999"),
                        message.message % message.message_args,
                    ),
                    message.__class__,
                )