diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2019-02-13 10:05:47 +0100 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-02-13 10:05:47 +0100 |
commit | c95f911a915ab88573bcc65217eed7f488281df6 (patch) | |
tree | a7e35f958c77b31446fa924f9d236f63cf758338 | |
parent | ee413f18b2dc5b8b626538d1cda64d01817e8765 (diff) | |
download | pylint-git-c95f911a915ab88573bcc65217eed7f488281df6.tar.gz |
Fixed a crash that occurred for ``bad-str-strip-call`` when ``strip()`` received ``None``
Close #2743
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | pylint/checkers/strings.py | 2 | ||||
-rw-r--r-- | pylint/test/functional/suspicious_str_strip_call.py | 1 |
3 files changed, 5 insertions, 1 deletions
@@ -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 |