summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaura Médioni <lmedioni@logilab.fr>2016-01-11 15:35:52 +0100
committerClaudiu Popa <pcmanticore@gmail.com>2016-01-15 21:56:13 +0200
commitee972478df98b2a7d22eff89dd51fa5338d588dd (patch)
tree776ad191df38b24d511a35be9e51a23e56a9eaf0
parent87806e6c211ff04b98f4fc6f5f9a4bc1ea0a7266 (diff)
downloadpylint-git-ee972478df98b2a7d22eff89dd51fa5338d588dd.tar.gz
Don't stringify nodes to check if they are None
extract and reuse a function checking for astroid.Const or astroid.Name.
-rw-r--r--pylint/checkers/base.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py
index 174642f50..c3e5064e5 100644
--- a/pylint/checkers/base.py
+++ b/pylint/checkers/base.py
@@ -197,6 +197,12 @@ def _determine_function_name_type(node):
return 'method'
+def _is_none(node):
+ return (node is None or
+ (isinstance(node, astroid.Const) and node.value is None) or
+ (isinstance(node, astroid.Name) and node.name == 'None')
+ )
+
def _has_abstract_methods(node):
"""
@@ -397,11 +403,7 @@ class BasicErrorChecker(_BasicChecker):
else:
values = [r.value for r in returns]
# Are we returning anything but None from constructors
- if [v for v in values
- if not (v is None or
- (isinstance(v, astroid.Const) and v.value is None) or
- (isinstance(v, astroid.Name) and v.name == 'None')
- )]:
+ if [v for v in values if not _is_none(v)]:
self.add_message('return-in-init', node=node)
elif node.is_generator():
# make sure we don't mix non-None returns and yields
@@ -1951,14 +1953,14 @@ class MultipleTypesChecker(BaseChecker):
if isinstance(target, (astroid.Tuple, astroid.Subscript)):
return
# ignore NoneType
- if node.value.as_string() == 'None':
+ if _is_none(node):
return
# check there is only one possible type for the assign node. Else we
# don't handle it for now
types = set()
try:
for var_type in node.value.infer():
- if var_type == astroid.YES or var_type.as_string() == 'None':
+ if var_type == astroid.YES or _is_none(var_type):
continue
var_type = var_type.pytype()
types.add(var_type)