-
Notifications
You must be signed in to change notification settings - Fork 111
Move B042 to B913 to not be enabled by deefault due to false positives #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Some false positives we need to iron out - Until someone wants to do that, let's not enable this check by default by moving to a B9XX - I've reserved B042 incase we want to ever move it back Test: - Move tests and see them stay passing as is ``` python3 -m venv --upgrade-dep /tmp/tf /tmp/tf/bin/pip install tox /tmp/tf/bin/tox -e py314 ... ============================================================================================= test session starts ============================================================================================== platform darwin -- Python 3.14.0, pytest-9.0.0, pluggy-1.6.0 cachedir: .tox/py314/.pytest_cache rootdir: /Users/cooper/repos/flake8-bugbear configfile: pyproject.toml plugins: hypothesis-6.147.0 collected 76 items tests/test_bugbear.py ............................................................................ [100%] ============================================================================================= 76 passed in 10.49s ============================================================================================== py314: commands[1]> coverage report -m Name Stmts Miss Cover Missing ------------------------------------------ bugbear.py 1116 20 98% 141-142, 152-163, 294, 308, 416, 758, 1275, 1454, 1471, 1605, 1713, 1792, 1910-1911, 2047-2048 ------------------------------------------ TOTAL 1116 20 98% py314: OK (18.98=setup[7.08]+cmd[11.76,0.15] seconds) congratulations :) (19.01 seconds) ```
| **B913**: Exception class with ``__init__`` should pass all args to ``super().__init__()`` in order to work | ||
| with ``copy.copy()``. It should also not take any kwargs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make more sense on how to use it? Welcome all improvements here ...
| "B913 Exception class with `__init__` should pass all args to " | ||
| "`super().__init__()` in order to work with `copy.copy()`. " | ||
| "It should also not take any kwargs." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to improve here too
There was a problem hiding this 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 pull request moves the B042 check to B913, making it disabled by default. The check validates that custom exception classes with __init__ methods properly pass all arguments to super().__init__() and do not accept kwargs.
Key changes:
- Renamed the B042 error code to B913 throughout the codebase
- Moved B913 to the
disabled_by_defaultlist to make it opt-in - Updated documentation to reflect that B042 is now reserved for future use
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| bugbear.py | Renamed check_for_b042 method to check_for_b913, updated all error references from B042 to B913, moved error definition from B042 to B913, and added B913 to disabled_by_default list |
| tests/eval_files/b913.py | Updated test expectations from B042 to B913 in all test case comments |
| README.rst | Updated B042 documentation to indicate it's reserved for future use, added B913 documentation, and updated changelog entries |
Comments suppressed due to low confidence (5)
tests/eval_files/b913.py:61
- This class does not call Anything.init during initialization. (MyError.init may be missing a call to a base class init)
tests/eval_files/b913.py:63 - This class does not call Anything.init during initialization. (MyException.init may be missing a call to a base class init)
tests/eval_files/b913.py:65 - This class does not call Anything.init during initialization. (MyExceptionGroup.init may be missing a call to a base class init)
tests/eval_files/b913.py:67 - This class does not call Anything.init during initialization. (MyWarning.init may be missing a call to a base class init)
tests/eval_files/b913.py:70 - This class does not call Anything.init during initialization. (ExceptionHandler.init may be missing a call to a base class init)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| UNRELEASED | ||
| ~~~~~~~~~~ | ||
|
|
||
| * B913: Move B042 to be optional by default. It checks for reminding to call super().__init__ in custom exceptions |
Copilot
AI
Nov 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing period at the end of the changelog entry. Should be 'It checks for reminding to call super().init() in custom exceptions.'
| * B913: Move B042 to be optional by default. It checks for reminding to call super().__init__ in custom exceptions | |
| * B913: Move B042 to be optional by default. It checks for reminding to call super().__init__ in custom exceptions. |
Test:
Addresses #525