From 601bd957ae7356ceaab02bbbb9ff9fea7564f7ff Mon Sep 17 00:00:00 2001 From: Max R Date: Mon, 23 Jan 2023 11:21:05 -0500 Subject: [PATCH] Recommend `.removeprefix()` or `.removesuffix()` in `B005` --- README.rst | 3 ++- bugbear.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 2cc7444..90c7fb0 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/bugbear.py b/bugbear.py index 5fea1c2..d532958 100644 --- a/bugbear.py +++ b/bugbear.py @@ -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"}