Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honour "# noqa: F401" comments #160

Closed
OddBloke opened this issue May 27, 2019 · 11 comments
Closed

Honour "# noqa: F401" comments #160

OddBloke opened this issue May 27, 2019 · 11 comments

Comments

@OddBloke
Copy link

Our codebase has to work as far back as Python 3.4, which doesn't have the typing module available. As such, all of our type annotations are in strings (so they are lazily evaluated during type checking and ignored when running normally) and our typing imports are conditional, with "# noqa: F401" appended to silence the flake8 warnings.

vulture doesn't honour these comments, and it seems like an obvious win for it to do so.

(Per http://flake8.pycqa.org/en/2.5.5/warnings.html, F401 is specifically the warning for "module imported but unused"; this matches very closely with Vulture's unused import warnings.)

@OddBloke
Copy link
Author

Looking through existing issues, I've seen that "# noqa" support has generally been rejected. Hopefully this request for just one specific form of noqa comment will be considered, as in my opinion, it would reduce the barrier to adoption substantially.

@jendrikseipp
Copy link
Owner

Since Python 3.4 has reached EOL and Vulture stopped testing for this version recently, I don't think Vulture should add workarounds that are only needed for this version. Your problem seems to be more general though. However, I don't understand why you need imports if all your type annotations are in strings. Could you please provide some example code?

@sersorrel
Copy link

Even if type hints are specified as strings, you still have to import the things used in type hints to tell the type checker what they are – it doesn't matter if you say foo: MyObject or foo: "MyObject" or foo = None # type: MyObject, if mypy doesn't know which MyObject you're referring to.

@jendrikseipp
Copy link
Owner

Thanks for the clarification! I agree that honoring F401 noqa comments makes sense. I'd be happy to review a pull request that makes this change.

@RJ722
Copy link
Contributor

RJ722 commented Sep 10, 2019

Regarding honoring # noqa comments, I think that once we have Vulture available as a flake-8 plugin (#161), we wouldn't need to develop/maintain this functionality ourselves. Am I thinking in the right direction?

@The-Compiler
Copy link
Contributor

@RJ722 I think you're right!

@jendrikseipp
Copy link
Owner

jendrikseipp commented Sep 10, 2019 via email

@RJ722
Copy link
Contributor

RJ722 commented Mar 31, 2020

@OddBloke are you okay with changing all of # noqa: F401, V104? (V104 is issue code Vulture raises for unused imports)

@jendrikseipp
Copy link
Owner

I guess it makes sense to let Vulture honour the F401 code as well.

@jendrikseipp
Copy link
Owner

I guess it makes sense to let Vulture honour the F401 code as well.

This has been implemented in 5e7fd66.

@OddBloke
Copy link
Author

OddBloke commented Apr 13, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants