Skip to content

Commit

Permalink
Merge pull request #6090 from DudeNr33/doc-bad-str-strip-call
Browse files Browse the repository at this point in the history
Add examples for ``bad-str-strip-call``
  • Loading branch information
DudeNr33 authored Apr 1, 2022
2 parents 6505c74 + 102646e commit c992072
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
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>`_

0 comments on commit c992072

Please sign in to comment.