-
Notifications
You must be signed in to change notification settings - Fork 107
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
B001 misses some bare excepts #97
Comments
Version
|
This is a very interesting find! Looks like we might not be visiting certain paths through the tree. If you could create a minimal example with this, that'd be helpful to test against and fix. |
Here's a repo you can clone with some examples in it. https://github.com/minusworld/flake8-B001-examples The three files used were pulled from: Let me know if there's anything else that would be helpful! |
The problem is your code is in Python 2 syntax. For instance, you have print statements without parenthesis, old style except clauses, and tuple expansion in function arguments. |
Then why does it have a whole section of Python 3 warnings? That's confusing. Can you elaborate on which parts don't work with Python 2? And shouldn't it just use whichever AST module is available in the running python interpreter? Or does each flake8 plugin run in its own interpreter? |
For when the syntax works in Python 3 but you have code using stuff that is from python 2, e.g., migrating or old habits. |
Many of the things those checks validate don't work in Python 3, so that doesn't really explain anything. In fact, none of them work in Python 3 except B303, right? If those spurious checks can't be removed, it'd be nice if the README loudly proclaimed that it doesn't work in Python2 (I guess we just call it PyPy2 now since the EOL of CPython2, lol). |
Maybe it's time to just drop our "limited" Python 2 support all together. It's past midpoint 2020. |
+1 |
1 similar comment
+1 |
All of them do not work in Python 3. That's the point, to warn about Python 2 code that does not work in Python 3, despite having the correct syntax. |
@joaoe And how long is any project in that state? It's an intermediate state that lasts maybe a day for most projects (if that) and there are existing tools that handle it better. That's precisely my point. I agree with @cooperlees. |
As long as they don't use a tool like bugbear to fix the issues :) And as long as developers don't make mistakes. |
@cooperlees - time to close the issue, since Python 2 support has been dropped? |
Nothing has been done to complete this. I think we need to remove these checks and all B30X too right? I guess we should make a plan and get this shipped. |
Closed by #182 I think 🙂 |
B001
and Flake8/pycodestyleE722
both check for bare_except, butB001
misses a lot of cases thatE722
finds.We noticed this when we tried running an internal tool that looks for overlaps in checks -- we are writing some of our own and don't want to overlap -- and found that every time B001 fires E722 also fires; but the reverse is not true.
Tool output:
B001 (6786) <-> E722 (34093): 13572 occurred at same line+path B001 implies E722: 100% E722 implies B001: 19%
I took a look at the implementations for B001 and E722 and found that bugbear uses the AST and E722 uses a regex:
Bugbear implementation uses AST.
Flake8 implementation uses regex.
From the implementation, it looks like B001 and E722 should hit the same locations every time.
We have a platform that lets us run static analysis over a bunch of open source repositories at the same time, so I ran vanilla flake8 and bugbear at the same time to see if there was a pattern, but one wasn't immediately obvious.
I thought this might be related to forgetting to call visit or something like that (I've been bitten by that before!) but the reason for this disparity wasn't clear to me... so I'm making this issue. Feel free to reach out to me if you have any other questions!
Here are some examples:
The text was updated successfully, but these errors were encountered: