Skip to content

Conversation

@cooperlees
Copy link
Collaborator

@cooperlees cooperlees commented Dec 2, 2025

  • Attempt to type all functions
  • Change namedtuples to tryuped NamedTuples
  • Add checks for optional / None variables
  • Lots of isinstance replacing getattr etc.
  • Add b005 to visit_ImportFrom
  • Found bug in check_for_b020 for reassigned_in_loop checking
    • Need to handle comprehensions

A lot of AI here, so happy to revert anything that does not make sense.

Test:

  • pre-commit run -a
  • tox -e mypy

Does more for #478 - Want to get to strict before closing that

- Attempt to type all functions
- Change namedtuples to tryuped NamedTuples
- Add checks for optional / None variables
- Lots of isinstance replacing getattr etc.
- Add b005 to visit_ImportFrom
- Found bug in check_for_b020 for reassigned_in_loop checking
  - Need to handle comprehensions

A lot of AI here, so happy to revert anything that
does not make sense.

Test:
- `pre-commit run -a`
- `tox -e mypy`
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR comprehensively adds type annotations to bugbear.py, converting namedtuples to typed NamedTuples and replacing dynamic attribute checking with proper type guards. The changes improve type safety and code maintainability without altering the core functionality.

Key Changes

  • Converted Context and error namedtuples to typed NamedTuple classes with explicit field annotations
  • Added type annotations to all function signatures including visitor methods and check functions
  • Replaced hasattr calls with isinstance checks for better type narrowing (e.g., in check_for_b017, check_for_b022)
  • Fixed a bug in check_for_b023 to properly handle comprehensions when detecting reassigned loop variables

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cooperlees cooperlees merged commit 785ad68 into main Dec 4, 2025
17 checks passed
@cooperlees cooperlees deleted the more_typing branch December 4, 2025 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants