summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2019-02-13 10:05:47 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2019-02-13 10:05:47 +0100
commitc95f911a915ab88573bcc65217eed7f488281df6 (patch)
treea7e35f958c77b31446fa924f9d236f63cf758338
parentee413f18b2dc5b8b626538d1cda64d01817e8765 (diff)
downloadpylint-git-c95f911a915ab88573bcc65217eed7f488281df6.tar.gz
Fixed a crash that occurred for ``bad-str-strip-call`` when ``strip()`` received ``None``
Close #2743
-rw-r--r--ChangeLog3
-rw-r--r--pylint/checkers/strings.py2
-rw-r--r--pylint/test/functional/suspicious_str_strip_call.py1
3 files changed, 5 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 18703237f..e4f6d2575 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,9 @@ What's New in Pylint 2.3.0?
Release date: TBA
+* Fixed a crash that occurred for ``bad-str-strip-call`` when ``strip()`` received ``None``
+
+ Close #2743
* Don't emit ``*-not-iterating`` checks for builtins consumed by ``itertools``
diff --git a/pylint/checkers/strings.py b/pylint/checkers/strings.py
index 8d1a101e7..dd2904301 100644
--- a/pylint/checkers/strings.py
+++ b/pylint/checkers/strings.py
@@ -345,7 +345,7 @@ class StringFormatChecker(BaseChecker):
):
if func.name in ("strip", "lstrip", "rstrip") and node.args:
arg = utils.safe_infer(node.args[0])
- if not isinstance(arg, astroid.Const):
+ if not isinstance(arg, astroid.Const) or not isinstance(arg.value, str):
return
if len(arg.value) != len(set(arg.value)):
self.add_message(
diff --git a/pylint/test/functional/suspicious_str_strip_call.py b/pylint/test/functional/suspicious_str_strip_call.py
index e859f25f8..bc3a27c27 100644
--- a/pylint/test/functional/suspicious_str_strip_call.py
+++ b/pylint/test/functional/suspicious_str_strip_call.py
@@ -7,3 +7,4 @@ __revision__ = 1
u''.strip('http://') # [bad-str-strip-call]
u''.lstrip('http://') # [bad-str-strip-call]
b''.rstrip('http://') # [bad-str-strip-call]
+"some_sensible_string".strip(None) # Don't crash