B008: resolve imported immutable calls - #574
Open
1678092075 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Module-scope tracking mishandles annotation-only assignments and misses some walrus rebindings.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds import-aware resolution for B008 immutable-call matching and shadowing detection.
Changes:
- Resolves absolute module imports and aliases.
- Tracks module-level rebinding.
- Adds evaluation tests and changelog entry.
File summaries
| File | Description |
|---|---|
bugbear.py |
Implements import resolution and shadow tracking. |
tests/eval_files/b008_extended.py |
Tests imports, aliases, and rebinding. |
tests/eval_files/b008_extended_shadowing.py |
Tests unqualified configuration shadowing. |
README.rst |
Adds the unreleased changelog entry. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+643
to
+644
| if self._b008_in_module_scope() and isinstance(node.ctx, (ast.Store, ast.Del)): | ||
| self._b008_shadow_imports((node.id,)) |
Comment on lines
+643
to
+644
| if self._b008_in_module_scope() and isinstance(node.ctx, (ast.Store, ast.Del)): | ||
| self._b008_shadow_imports((node.id,)) |
cooperlees
requested changes
Sep 2, 2026
cooperlees
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for this. This seems mostly there, but maybe we can add a test case + handle the walrus operator too? (if I'm understanding correctly copilots finding)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #252.
Summary
extend-immutable-callsValidation
tox -e py313— 81 passed, 1 skipped; 97% coveragepre-commit run --all-files— isort, Black, flake8, and rstcheck passedgit diff --checkScope
This intentionally resolves only direct absolute module-level imports. Nested/local, relative, and star-import resolution remain out of scope, and B039 behavior is unchanged.