diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-08-28 16:33:50 +0300 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-08-28 16:33:50 +0300 |
commit | cd74a130e1bc71930db4482132c48076de4af50f (patch) | |
tree | b1a175e65aeffb2df683ea9278cf9cbbd8f93ff6 | |
parent | 703ec99df8c2c7e8289974a0a64fc1fd10eea913 (diff) | |
download | astroid-git-cd74a130e1bc71930db4482132c48076de4af50f.tar.gz |
Don't raise StopIteration in InferenceContext.push, instead exit from the generator by doing an early return
This makes astroid compliant with PEP 479 changes, since in the future it will be
prohibited to exit from a generator by raising a StopIteration.
-rw-r--r-- | astroid/bases.py | 21 | ||||
-rw-r--r-- | astroid/context.py | 5 |
2 files changed, 15 insertions, 11 deletions
diff --git a/astroid/bases.py b/astroid/bases.py index f455b8df..cf1a52d8 100644 --- a/astroid/bases.py +++ b/astroid/bases.py @@ -160,20 +160,21 @@ class Instance(Proxy): context = contextmod.InferenceContext() try: # avoid recursively inferring the same attr on the same class - context.push((self._proxied, name)) + if context.push((self._proxied, name)): + return + # XXX frame should be self._proxied, or not ? get_attr = self.getattr(name, context, lookupclass=False) - return _infer_stmts( - self._wrap_attr(get_attr, context), - context, - frame=self, - ) + for stmt in _infer_stmts(self._wrap_attr(get_attr, context), + context, frame=self): + yield stmt except exceptions.NotFoundError: try: # fallback to class'igetattr since it has some logic to handle # descriptors - return self._wrap_attr(self._proxied.igetattr(name, context), - context) + for stmt in self._wrap_attr(self._proxied.igetattr(name, context), + context): + yield stmt except exceptions.NotFoundError: raise exceptions.InferenceError(name) @@ -350,7 +351,9 @@ def path_wrapper(func): """wrapper function handling context""" if context is None: context = contextmod.InferenceContext() - context.push(node) + if context.push(node): + return + yielded = set() for res in _func(node, context, **kwargs): # unproxy only true instance, not const, tuple, dict... diff --git a/astroid/context.py b/astroid/context.py index bb2422ae..5a2ea525 100644 --- a/astroid/context.py +++ b/astroid/context.py @@ -17,7 +17,6 @@ # with astroid. If not, see <http://www.gnu.org/licenses/>. """Various context related utilities, including inference and call contexts.""" - import contextlib import itertools @@ -38,8 +37,10 @@ class InferenceContext(object): def push(self, node): name = self.lookupname if (node, name) in self.path: - raise StopIteration() + return True + self.path.add((node, name)) + return False def clone(self): # XXX copy lookupname/callcontext ? |