B906 checks all classes, not just AST visitors
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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