Python: pyflakes 没有解释我的评论

Python: pyflakes not interpreting noqa comment

我的 pyflakesnoqa 评论有些奇怪。

我有一个 class 类似于下面的 (MyExample):

从命令行消息调用 pyflakes redefinition of unused 'enter_yes_no' from line 25。因此,我添加了 # noqa: F811 评论,但消息并没有消失。

我的问题:


源代码

姓名:pyflakes_f811_overload.py

#!/usr/bin/env python3

"""Testing pyflakes F811."""


from abc import ABC
from enum import Enum
from typing import overload, Union


class YesNoOptions(Enum):
    """Enum representing basic states of a yes/no."""

    YES = "YES"
    NO = "NO"


class MyExample(ABC):  # pylint: disable=too-few-public-methods
    """Example class."""

    # pylint: disable=no-self-use
    @overload
    def enter_yes_no(self, input_: YesNoOptions):
        """Enter yes/no using an enum."""
        ...

    # pylint: disable=no-self-use
    @overload  # noqa: F811
    def enter_yes_no(self, input_: str):
        """Enter yes/no using a string."""
        ...

    def enter_yes_no(self, input_: Union[YesNoOptions, str]):  # noqa: F811
        """Enter yes/no."""
        if isinstance(input_, str):
            parsed_input = input_.upper()
        elif isinstance(input_, YesNoOptions):
            parsed_input = input_.value
        else:
            raise NotImplementedError(
                f"Did not implement yes/no parsing for input {repr(input_)} of "
                f"type {type(input_)}."
            )

        print(f"User entered: {parsed_input}")


复制

pyflakes 是通过命令行这样调用的:

(pyflakes_venv) ➜  pyflakes_f811_test pyflakes ./pyflakes_f811_overload.py
./pyflakes_f811_overload.py:28: redefinition of unused 'enter_yes_no' from line 22
./pyflakes_f811_overload.py:33: redefinition of unused 'enter_yes_no' from line 28

包版本:

python==3.6.5
pycodestyle==2.4.0
pyflakes==2.1.1
prospector==1.2.0

Pyflakes 不支持忽略特定行的 noqa 注释。你可以查看他们的源代码https://github.com/PyCQA/pyflakes that there is not a mention of noqa. The noqa feature is only in flake8。由于 flake8 使用 Pyflakes 我建议你切换到 flake8:

pip install flake8
flake8 ./pyflakes_f811_overload.py

关于你的@overload装饰器的特殊问题,虽然它已经在master分支(#435)中修复,但还没有发布(截至02/April/2020).