Comments (2)
Nice find. Will happily take a fix to include supporting this.
from flake8-bugbear.
I'm interested in doing a PR for this fix, however I have a question about how best to go about avoiding false positives.
The most obvious solution modifies the check for B017
to also be "positive" for an ast.Name object with id == "raises"
, but this would also falsely flag from Dummy import raises
.
After looking further into the code, the most straightforward solution, to me, seems to me
- Add
visit_ImportFrom(self, node)
that then callsvisitImport(...)
to perform the same checks.- As-is, the
ast.ImportFrom
node is not handled in any way - I have verified that the
B005
check method is entered with both types of import nodes after this change
- As-is, the
- Modify the logic of
check_for_b005
to account for the possibility of anast.ImportFrom
node- It seems like the solution would be to add an "or" to the first condition,
if isinstance(node, ast.Import) or isinstance(node, ast.ImportFrom)
so that the node would be added toself._b005_imports
- Is there anything else that would need to be changed to support
ast.ImportFrom
node? If so, would that be expected to be don as part of this PR, or create a new issue to log the needed change?
- It seems like the solution would be to add an "or" to the first condition,
- Modify the logic in
check_for_b017
to check for:ast.Name
node withid = "raises"
and anast.ImportFrom
node in_b005_imports
that indicates thefrom pytest import raises
node
- This check should account for the possibility that the node is
from pytest import ..., raises, ...
(multiple imports in one line) - Would only the check for
raises()
have anmatches
argument be the only check that should be added (if possible)?
I want to make sure this approach is a reasonable solution before I get too far into the development, particularly the changes to check_for_b005
and how to handle the ast.ImportFrom
node. Do you think this makes sense for a solution?
from flake8-bugbear.
Related Issues (20)
- False positive `B023` with loop's local variable HOT 3
- B109: Documentation/error message is wrong about the violation scope HOT 2
- False-positive B902 on custom metaclass extending ABCMeta HOT 8
- Add flake8 to pre-commit config HOT 3
- B902: False positive when using the attrs library HOT 6
- Policy on bugbears in usage of popular third party libraries HOT 2
- B026 False negative on class methods HOT 1
- Improve unit test runner HOT 2
- Feature request: a rule for calling super().__init__() in custom exception's __init__() HOT 2
- Feature request: a rule for detecting calls to mutate all-caps "constants" HOT 1
- B035: False positive for comprehensions that use a walrus operator
- Couple new rule suggestions HOT 2
- Rule to detect changes to iterable object of loop HOT 5
- Error in latest version of flake8-bugbear 24.1.15 HOT 4
- B038 false positive in 24.1.15 + 24.1.16 HOT 5
- B018 doesn't trigger for useless expressions involving multiple variables HOT 3
- B909 improvements HOT 4
- B038 false positives HOT 5
- How to handle B015 within pytest.raises blocks
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flake8-bugbear.