Skip to content

Conversation

fennr
Copy link

@fennr fennr commented May 29, 2025

close #513

I used B043 because I see PR with B042

@fennr
Copy link
Author

fennr commented May 29, 2025

@cooperlees check my PR please

@cooperlees cooperlees requested a review from Copilot September 8, 2025 19:54
Copy link
Contributor

@Copilot 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 adds a new linting rule B043 that detects when delattr() is called with a constant string attribute name, suggesting to use direct attribute deletion instead.

  • Adds rule B043 to detect delattr(obj, "constant") usage patterns
  • Provides test cases demonstrating valid and invalid usage patterns
  • Updates documentation to explain the rule and its rationale

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/eval_files/b043.py Test cases showing valid dynamic usage vs invalid constant usage of delattr
bugbear.py Core logic to detect delattr calls with constant string arguments and error definition
README.rst Documentation explaining B043 rule and recommending del x.attr over delattr(x, 'attr')

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

"B043": Error(
message=(
"B043 Do not call delattr with a constant attribute value, "
"it is not any safer than normal property access."
Copy link
Preview

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

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

The error message mentions 'normal property access' but the recommended alternative is attribute deletion (del x.attr), not property access. Consider changing to 'it is not any safer than normal attribute deletion.'

Suggested change
"it is not any safer than normal property access."
"it is not any safer than normal attribute deletion."

Copilot uses AI. Check for mistakes.


.. _B043:

**B043**: Do not call ``delattr(x, 'attr')``, instead use ``del x.attr``.
Copy link
Preview

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

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

There's a trailing space after the period on line 293. Remove the trailing whitespace.

Suggested change
**B043**: Do not call ``delattr(x, 'attr')``, instead use ``del x.attr``.
**B043**: Do not call ``delattr(x, 'attr')``, instead use ``del x.attr``.

Copilot uses AI. Check for mistakes.

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.

New rule to check delattr with constant
1 participant