bad-str-strip-call / E1310ΒΆ
Message emitted:
Suspicious argument in %s.%s call
Description:
The argument to a str.{l,r,}strip call contains a duplicate character,
Problematic code:
hello_world.py
:
"Hello World".strip("Hello") # [bad-str-strip-call]
# >>> ' World'
remove_abc_from_both_side.py
:
"abcbc def bacabc".strip("abcbc ") # [bad-str-strip-call]
# >>> 'def'
Correct code:
hello_world.py
:
"Hello World".strip("Helo")
# >>> ' World'
remove_abc_from_both_side.py
:
"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:
Documentation: str.strip([chars])
Created by the string checker.