Skip to content

Commit d8c5796

Browse files
authored
Merge pull request #587 from LuisFigueroaG/fix/b005-message
B005: mention repeated characters in the message
2 parents c1cdd3d + a1b3159 commit d8c5796

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎README.rst‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ results. Use ``callable(x)`` for consistent results.
8787

8888
.. _B005:
8989

90-
**B005**: Using ``.strip()`` with multi-character strings is misleading
91-
the reader. It looks like stripping a substring. Move your
90+
**B005**: Using ``.strip()`` with a multi-character string that repeats
91+
characters is misleading the reader. It looks like stripping a substring,
92+
but the argument is treated as a set of characters. Move your
9293
character set to a constant if this is deliberate. Use
9394
``.replace()``, ``.removeprefix()``, ``.removesuffix()`` or regular
9495
expressions to remove string fragments.
@@ -528,6 +529,8 @@ UNRELEASED
528529

529530
* B045: detect reuse of an enclosing loop's control variable in a nested loop
530531
in the same scope (#360).
532+
* B005: say in the message that only strings with repeated characters are
533+
reported, since ``.strip("abc")`` style character sets are fine (#91)
531534
* B031: only treat a bare ``groupby()`` call as ``itertools.groupby`` when the
532535
module doesn't bind ``groupby`` to something else, such as its own
533536
``def groupby`` (#356)

‎bugbear.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,9 +3183,10 @@ def __call__(self, lineno: int, col: int, vars: tuple[object, ...] = ()) -> erro
31833183
),
31843184
"B005": Error(
31853185
message=(
3186-
"B005 Using .strip() with multi-character strings is misleading "
3187-
"the reader. It looks like stripping a substring. Move your "
3188-
"character set to a constant if this is deliberate. Use "
3186+
"B005 Using .strip() with a multi-character string that repeats "
3187+
"characters is misleading the reader. It looks like stripping a "
3188+
"substring, but the argument is treated as a set of characters. "
3189+
"Move your character set to a constant if this is deliberate. Use "
31893190
".replace(), .removeprefix(), .removesuffix(), or regular "
31903191
"expressions to remove string fragments."
31913192
)

0 commit comments

Comments
 (0)