Giter Site home page Giter Site logo

Comments (2)

cooperlees avatar cooperlees commented on July 18, 2024

Nice find. Will happily take a fix to include supporting this.

from flake8-bugbear.

azinneck0485 avatar azinneck0485 commented on July 18, 2024

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

  1. Add visit_ImportFrom(self, node) that then calls visitImport(...) 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
  2. Modify the logic of check_for_b005 to account for the possibility of an ast.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 to self._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?
  3. Modify the logic in check_for_b017 to check for: ast.Name node with id = "raises" and an ast.ImportFrom node in _b005_imports that indicates the from 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 an matches 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.