Skip to content

Conversation

@cooperlees
Copy link
Collaborator

  • 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)

Addresses #525

- 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)
```
Comment on lines +377 to +378
**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.
Copy link
Collaborator Author

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 ...

Comment on lines +2475 to +2477
"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."
Copy link
Collaborator Author

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

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 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_default list 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


💡 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
Copy link

Copilot AI Nov 9, 2025

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.'

Suggested change
* 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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants