Skip to content
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

Recommend .removeprefix() or .removesuffix() in B005 #339

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ results. Use ``callable(x)`` for consistent results.
**B005**: Using ``.strip()`` with multi-character strings is misleading
the reader. It looks like stripping a substring. Move your
character set to a constant if this is deliberate. Use
``.replace()`` or regular expressions to remove string fragments.
``.replace()``, ``.removeprefix()``, ``.removesuffix()`` or regular
expressions to remove string fragments.

**B006**: Do not use mutable data structures for argument defaults. They
are created during function definition time. All calls to the function
Expand Down
3 changes: 2 additions & 1 deletion bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,8 @@ def visit_Lambda(self, node):
"B005 Using .strip() with multi-character strings is misleading "
"the reader. It looks like stripping a substring. Move your "
"character set to a constant if this is deliberate. Use "
".replace() or regular expressions to remove string fragments."
".replace(), .removeprefix(), .removesuffix(), or regular "
"expressions to remove string fragments."
)
)
B005.methods = {"lstrip", "rstrip", "strip"}
Expand Down