diff options
author | Bryce Guinta <bryce.paul.guinta@gmail.com> | 2018-02-10 16:50:49 -0700 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-04-05 08:44:34 +0200 |
commit | 0691de5d94eb069e2954056fcaf541c89650f785 (patch) | |
tree | 914d2ff3dada2dc6198858c60403a50d4548a03a | |
parent | 306c651d6bbcfe9e426f82e8555cc7fc2962752b (diff) | |
download | pylint-git-0691de5d94eb069e2954056fcaf541c89650f785.tar.gz |
Fix no-context-manager test breakage in due to astroid changes
Require no-context-manager to infer paths before walking the tree
Fixes #1874
-rw-r--r-- | pylint/checkers/typecheck.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 9df65a5de..9d338be84 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -36,6 +36,7 @@ import operator import re import shlex import sys +import types import six @@ -81,6 +82,15 @@ def _unflatten(iterable): # We're interested only in the first element. yield elem +def _flatten_container(iterable): + # Flatten nested containers into a single iterable + for item in iterable: + if isinstance(item, (list, tuple, types.GeneratorType)): + for elem in _flatten_container(item): + yield elem + else: + yield item + def _is_owner_ignored(owner, name, ignored_classes, ignored_modules): """Check if the given owner should be ignored @@ -1143,8 +1153,12 @@ accessed. Python regular expressions are accepted.'} # manager and give up, otherwise emit not-context-manager. # See the test file for not_context_manager for a couple # of self explaining tests. - for path in six.moves.filter(None, _unflatten(context.path)): - scope = path.scope() + + # Retrieve node from all previusly visited nodes in the the inference history + context_path_names = filter(None, _unflatten(context.path)) + inferred_paths = _flatten_container(path.infer() for path in context_path_names) + for inf_path in inferred_paths: + scope = inf_path.scope() if not isinstance(scope, astroid.FunctionDef): continue if decorated_with(scope, |