Repository navigation
chore: add type hints for bugbear - #611
Merged
Merged
Conversation
phalberg
commented
Oct 29, 2026
|
|
||
| underscore_indexes = [ | ||
| index for index, target in enumerate(targets) if target.id == "_" | ||
| index for index, target in enumerate(targets) if isinstance(target, ast.Name) and target.id == "_" |
Contributor
Author
There was a problem hiding this comment.
This seems somewhat useless to check, since we have L2776-L2777 but I am not sure if there are simpler ways to satisfy mypy -- open for suggestions :)
phalberg
force-pushed
the
chore/mypy_on_bugbear
branch
from
October 29, 2026 19:52
c242921 to
f2e6a06
Compare
phalberg
marked this pull request as ready for review
October 29, 2026 19:54
cooperlees
approved these changes
Oct 31, 2026
cooperlees
left a comment
Collaborator
There was a problem hiding this comment.
AI review on behalf of @cooperlees — I checked out the PR branch, verified each hunk, ran mypy and the test suite.
Verdict: Approve — all 6 changes are behavior-preserving typing fixes:
stack: list[ast.AST]+extend()— same aslist(body), fixesIterator[AST]vsIterable[stmt]error. Good._only_comment_after(node.value)instead of(node)— matches theast.exprsignature.Exprand itsConstantvalue share the same span so observable behavior is identical. Correct fix.safe_functions: list[AsyncFunctionDef | Lambda | FunctionDef]— pure annotation matchingFUNCTION_NODES. Good.- B913
isinstance(target, ast.Name)guard — redundant given the early-return above it, but harmless and satisfiesexpr has no attribute id. No behavior change. Good. outer_names: set[str]— pure annotation. Good.- B046
kw_value is None: return— previouslyvalue=Nonewould just fall through theisinstancechecks with no error; early return is equivalent and narrowsexpr | Nonetoexpr. Correct and clearer.
Verification: mypy bugbear.py is clean (only unrelated missing flake8.exceptions stubs), pytest tests/ -q passes (142 passed, 2 skipped).
Note: This review was written by AI on behalf of cooperlees.
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.
Summary
Adding some type hints for
bugbear.py!Issue
Part of #478.
Desc
While running mypy on
bugbear.py(not strict, we will get to that one hopefully 🚀) I got the following errors:It seems happy after this change:
Note: Please do double check if all of these types make sense though, I must admit that i have not checked thoroughly neither am i completely used to the codebase yet...