PyCQA / PyCQA/flake8-bugbear

B906 checks all classes, not just AST visitors

Open
#359 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.1k
Forks
123
Avg merge
2d 5h
Merged PRs (30d)
5

Description

I'm seeing some false-positives from B906 where we have node visitors that are not using the stdlib ast library:

import libcst


class CSTVisitor(libcst.CSTVisitor):
    def visit_ClassDef(self, node):
        pass
$ flake8 --select=B906 t.py
t.py:5:5: B906 `visit_` function with no further calls to a visit function, which might prevent the `ast` visitor from properly visiting all nodes. Consider adding a call to `self.generic_visit(node)`.

In this case, libcst.CSTVisitor does not have a generic_visit method (and the error message explicitly talks about ast, which is confusing).

Should this rule make sure it only applies to ast visitors rather than other classes that have a visit_ method?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing B906 with the provided libcst.CSTVisitor example and the flake8 --select=B906 t.py command. Trace the B906 rule and its tests to determine how visitor classes are identified. Done means non-stdlib AST visitors are not incorrectly reported, while genuine AST visitor cases retain the intended diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.