From 6744f44b7d50024283972badb396d3d357a71c74 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Fri, 20 Nov 2015 13:10:36 +0200 Subject: Simplify the unflatten algorithm in order to not use NodeNG anymore. --- pylint/checkers/typecheck.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 0f5d7af..da9daf7 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -28,6 +28,7 @@ import astroid.arguments from astroid import exceptions from astroid import objects from astroid import node_classes +from astroid import bases import six from pylint.interfaces import IAstroidChecker, INFERENCE, INFERENCE_FAILURE @@ -51,12 +52,13 @@ STR_FORMAT = "%s.str.format" % BUILTINS def _unflatten(iterable): - for elem in iterable: + for index, elem in enumerate(iterable): if (isinstance(elem, collections.Sequence) and not isinstance(elem, six.string_types)): - for subelem in _unflatten(elem): - yield subelem - elif isinstance(elem, node_classes.NodeNG): + for elem in _unflatten(elem): + yield elem + elif elem and not index: + # We're interested only in the first element. yield elem @@ -735,7 +737,7 @@ accessed. Python regular expressions are accepted.'} if infered is None or infered is astroid.YES: continue - if isinstance(infered, astroid.bases.Generator): + if isinstance(infered, bases.Generator): # Check if we are dealing with a function decorated # with contextlib.contextmanager. if decorated_with(infered.parent, ['contextlib.contextmanager']): -- cgit v1.2.1