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
Warn against using yield and return x #2
Comments
As Victor and Xiang noted on the original bug, this is a new feature of Python and not a bug. In this sense, linting against this would for sure create false positives. Even in your pull request you don't really suggest what the user should do (note that all other messages have suggestions). And if you suggested users to not use
How did this "bite" you? |
See the attached example in that bug. I wrote the |
What we are trying to explain to you is that mere existence of B0xx - downright bugs or design issues. No excuse having code like this. B3xx - likely valid Python 2 code that will not work on Python 3. While these can have false positives, they would trip up a human reviewer in the same way. Your proposed warning is in a different category of "it might sometimes be a problem for people unfamiliar with a new feature of the language". You would be better served type annotating your code and running a type checker against it. The generator annotation is specifically designed for the problem you are encountering, see here: https://www.python.org/dev/peps/pep-0484/#annotating-generator-functions-and-coroutines |
I'm aware that this falls into a different category. It's a quite opinionated check, and whether it has a place in a linter simply depends on what kind of linter the author wants to make. If you don't want it, that's totally fine. Regarding type annotations -- I might as well use an actually statically typed language :) |
I was pondering adding a class of disabled-by-default guidance warnings. If you can figure out how we can introduce a warning that wouldn't be enabled by default unless specifically listed in your config, and creating a new class for them (say B9xx), I would be willing to merge your proposed warning. |
Happy to hear that! I suspect the best way to go about this are options, unless there's a Flake8-specific API I'm not aware of. @sigmavirus24 is there a way to do disabled-by-default warnings in Flake8 plugins? |
pycodestyle (formerly pep8) does have a bunch of disabled-by-default warning codes: Check out how they do it. |
pycodestyle is not a flake8 extension as far as I can see, i.e. flake8 hooks into pycodestyle, not the other way around. It comes with its own CLI and defines its own --ignore option there. Anyway I updated my code in #3 by reading through flake8's sourcecode. I think the used methods are supposed to be used like that, but I'm not sure. I didn't find any documentation. |
So Flake8 2.4+ (I think it's 2.4) allows you to annotate a check with an Sorry for the delay, I'm not quite well. |
That appears to be per-plugin, we need a per-warning-code solution. Probably could still be used by defining multiple plugins + entrypoints in one package.
You mean So @ambv, do we need to support |
Also @sigmavirus24 I respond to some mail after two months, so... which delay? 😆 Get well though. |
Correct. Hacking presently uses it with multiple plugins in the one package.
I hadn't looked but that is exactly what I mean. =) |
We don't need to support flake8 < 3.0, no. |
Cool, I bumped the requirement in |
Hmm, flake8==3.0.4 and the latest flake8-bugbear apparently don't have this new check disabled by default! Sorry, I should've checked this before asking for review. At first glance I can't see anything in flake8-bugbear that would be the cause of this. |
Are you sure? This is not my experience:
The one thing that DOESN'T work is that selecting B9 still filters out B901 (you have to explicitly name each warning):
|
Yeah I'm a fool, forgot that I 1.) have a |
It's opinionated see PyCQA/flake8-bugbear#2 and every current warning is a false positive.
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/asottile/pyupgrade: v2.37.2 → v2.37.3](asottile/pyupgrade@v2.37.2...v2.37.3) - https://github.com/Pierre-Sassoulas/black-disable-checker/: v1.1.0 → v1.1.1 - [github.com/PyCQA/flake8: 4.0.1 → 5.0.3](PyCQA/flake8@4.0.1...5.0.3) * Disable line too long and line break before binary operator As there's a lot of the format and the latter is incompatible with black. * [flake8] Deactivate the check for return and yield together It's opinionated see PyCQA/flake8-bugbear#2 and every current warning is a false positive. * Explain falke8 disables Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com> Co-authored-by: Daniël van Noord <13665637+DanielNoord@users.noreply.github.com>
Python 3 allows mixing of return-with-value and yield in the same function. I got bitten by this behavior multiple times, so I want to write a flake8 plugin for it. I wonder if I should add the lint to this package instead of making a separate one. What do you think?
The text was updated successfully, but these errors were encountered: