prospector
prospector copied to clipboard
[BUG] pyflakes not seeing `# noqa` comment when run on module as opposed to directory
Describe the bug
I am using the tool pyflakes within prospector. I have found pyflakes has two different outputs, depending on how prospector's PATH arg is set:
PATHis current directory:prospector .-->Messages Found: 0PATHis module (in current directory):prospector ./pyflakes_f811_overload.py-->Messages Found: 2. Why? It seems pyflakes is no longer interpreting# noqacomment
To Reproduce
- Make virtualenv called
pyflakes_venv, upgrade pip and runpip install pycodestyle==2.4.0 pyflakes==2.1.1 prospector==1.2.0 - Make a directory named
pyflakes_f811_test, place the below (see bottom)pyflakes_f811_overload.pyfile inside, andcdinto the directory - Invoke
prospectorlike so:
(pyflakes_venv) ➜ pyflakes_f811_test prospector --no-external-config --tool pyflakes .
Check Information
=================
Started: 2020-04-02 10:39:20.057267
Finished: 2020-04-02 10:39:20.065109
Time Taken: 0.01 seconds
Formatter: grouped
Profiles: default, no_doc_warnings, no_test_warnings, strictness_medium, strictness_high, strictness_veryhigh, no_member_warnings
Strictness: None
Libraries Used:
Tools Run: pyflakes
Messages Found: 0
No messages found, as expected. This means pyflakes interprets the # noqa: F811 comments, as expected.
- Invoke
prospectoragain, like so: (this is the bug)
(pyflakes_venv) ➜ pyflakes_f811_test prospector --no-external-config --tool pyflakes ./pyflakes_f811_overload.py
Messages
========
pyflakes_f811_overload.py
Line: 31
pyflakes: F811 / redefinition of unused 'enter_yes_no' from line 25 (col 5)
Line: 36
pyflakes: F811 / redefinition of unused 'enter_yes_no' from line 31 (col 5)
Check Information
=================
Started: 2020-04-02 10:39:51.803464
Finished: 2020-04-02 10:39:51.811182
Time Taken: 0.01 seconds
Formatter: grouped
Profiles: default, no_doc_warnings, no_test_warnings, strictness_medium, strictness_high, strictness_veryhigh, no_member_warnings
Strictness: None
Libraries Used:
Tools Run: pyflakes
Messages Found: 2
This time, pyflakes seemingly doesn't interpret the # noqa: F811 comments, as it raises 2 messages.
Expected behavior
I expect in both cases, pyflakes to properly interpret the # noqa: F811 comments (aka 0 messages found).
What is going on here? Should I just never invoke prospector (with the pyflakes tool) on a given. module, and always on a directory?
Environment (please complete the following information):
- OS:
macOS Mojave 10.14.3 - Tool:
pyflakes==2.1.1(andpycodestyle==2.4.0) - Prospector version:
1.2.0 - Python version:
3.6.5
Additional context
(pyflakes_venv) ➜ pyflakes_f811_test pip freeze
astroid==2.3.3
dodgy==0.2.1
isort==4.3.21
lazy-object-proxy==1.4.3
mccabe==0.6.1
pep8-naming==0.4.1
prospector==1.2.0
pycodestyle==2.4.0
pydocstyle==5.0.2
pyflakes==2.1.1
pylint==2.4.4
pylint-celery==0.3
pylint-django==2.0.12
pylint-flask==0.6
pylint-plugin-utils==0.6
PyYAML==5.3.1
requirements-detector==0.6
setoptconf==0.2.0
six==1.14.0
snowballstemmer==2.0.0
typed-ast==1.4.1
wrapt==1.11.2
Sample File
Name: 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}")
Actually, to follow up, https://stackoverflow.com/a/60999389/11163122 informed me that pyflakes doesn't support noqa comments. So this leads to a new question: why is prospector listening to the noqa comments when run on a directory, but not on a module?
Thanks for reporting that. I should take a look at this over the weekend and will get back here after it.
Another not working example:
$> echo "import sys # noqa: F401" > test.py
$> prospector -t pyflakes test.py
Check Information
=================
Started: 2022-10-07 11:23:54.304464
Finished: 2022-10-07 11:23:54.305180
Time Taken: 0.00 seconds
Formatter: grouped
Profiles: default, no_doc_warnings, no_test_warnings, strictness_medium, strictness_high, strictness_veryhigh, no_member_warnings
Strictness: None
Libraries Used: django, flask
Tools Run: pyflakes
Messages Found: 0
$> prospector -t pyflakes ./test.py
Messages
========
test.py
Line: 1
pyflakes: F401 / 'sys' imported but unused (col 1)
Check Information
=================
Started: 2022-10-07 11:23:58.046490
Finished: 2022-10-07 11:23:58.047244
Time Taken: 0.00 seconds
Formatter: grouped
Profiles: default, no_doc_warnings, no_test_warnings, strictness_medium, strictness_high, strictness_veryhigh, no_member_warnings
Strictness: None
Libraries Used: django, flask
Tools Run: pyflakes
Messages Found: 1
$> prospector --version
prospector 1.7.7
Notice the only difference here that changes the output of the tool is passing the file as test.py or ./test.py