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

Add examples for bad-str-strip-call #6090

Merged
merged 1 commit into from
Apr 1, 2022
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
2 changes: 2 additions & 0 deletions doc/data/messages/b/bad-str-strip-call/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
my_string = "Hello World"
my_string.strip("Hello") # [bad-str-strip-call]
7 changes: 7 additions & 0 deletions doc/data/messages/b/bad-str-strip-call/details.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
A common misconception is that ``str.strip('Hello')`` removes the *substring* ``'Hello'`` from the beginning and end of the string.
This is **not** the case.
From the `documentation <https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.strip>`_:

> The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped

Duplicated characters in the ``str.strip`` call, besides not having any effect on the actual result, may indicate this misunderstanding.
2 changes: 2 additions & 0 deletions doc/data/messages/b/bad-str-strip-call/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
my_string = "Hello World"
my_string.strip("Helo")
1 change: 1 addition & 0 deletions doc/data/messages/b/bad-str-strip-call/related.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Documentation: `str.strip([chars]) <https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.strip>`_