diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2016-03-16 11:18:50 +0000 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2016-03-16 11:18:50 +0000 |
commit | 318bf253195e489ad21c3bf9df236ac49a3d293c (patch) | |
tree | 640514b0599adc54e27df06a21174fb62a940858 /pylint/checkers/classes.py | |
parent | b22b7028fae55f189dff25468e0abcc16bd1b445 (diff) | |
download | pylint-git-318bf253195e489ad21c3bf9df236ac49a3d293c.tar.gz |
Filter non Const nodes instead of checking for AttributeError.
Diffstat (limited to 'pylint/checkers/classes.py')
-rw-r--r-- | pylint/checkers/classes.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index fd4c4b252..dd0333077 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -1093,13 +1093,15 @@ class SpecialMethodsChecker(BaseChecker): self.add_message('non-iterator-returned', node=node) def _check_len(self, node): - infered = _safe_infer_call_result(node, node) - if infered is None or infered is astroid.util.Uninferable: + inferred = _safe_infer_call_result(node, node) + if inferred is None or inferred is astroid.util.Uninferable: return - try: - value = infered.value - except AttributeError: - value = None + + if not isinstance(inferred, astroid.Const): + self.add_message('invalid-length-returned', node=node) + return + + value = inferred.value if not isinstance(value, six.integer_types) or value < 0: self.add_message('invalid-length-returned', node=node) |