bad-str-strip-call / E1310#

Message emitted:

Suspicious argument in %s.%s call


The argument to a str.{l,r,}strip call contains a duplicate character,

Problematic code:

"Hello World".strip("Hello")  # [bad-str-strip-call]
# >>> ' World'

"abcbc def bacabc".strip("abcbc ")  # [bad-str-strip-call]
# >>> 'def'

Correct code:

"Hello World".strip("Helo")
# >>> ' World'

"abcbc def bacabc".strip("abc ")
# >>> 'def'

Additional details:

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:

> 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.

Related links:

Created by the string checker.