diff options
author | Emile Anclin <emile.anclin@logilab.fr> | 2010-03-17 13:11:50 +0100 |
---|---|---|
committer | Emile Anclin <emile.anclin@logilab.fr> | 2010-03-17 13:11:50 +0100 |
commit | 6f75627f757eedd70ce7390345066212040c6e0b (patch) | |
tree | 402e6a271403ec965c10b0440b92adde8f5b1348 /bases.py | |
parent | a246fa3f8175bdcba9282439b8cab413de285a43 (diff) | |
download | astroid-6f75627f757eedd70ce7390345066212040c6e0b.tar.gz |
remove InferenceContext.startingfrom; use a set for path_wrapper
Diffstat (limited to 'bases.py')
-rw-r--r-- | bases.py | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -36,7 +36,7 @@ except ImportError: class BaseClass: pass - +from logilab.common.compat import set from logilab.astng.utils import REDIRECT from logilab.astng._exceptions import (InferenceError, ASTNGError, NotFoundError, UnresolvableName) @@ -65,10 +65,9 @@ class Proxy(BaseClass): class InferenceContext(object): - __slots__ = ('startingfrom', 'path', 'lookupname', 'callcontext', 'boundnode') + __slots__ = ('path', 'lookupname', 'callcontext', 'boundnode') - def __init__(self, node=None, path=None): - self.startingfrom = node # XXX useful ? + def __init__(self, path=None): if path is None: self.path = [] else: @@ -88,7 +87,7 @@ class InferenceContext(object): def clone(self): # XXX copy lookupname/callcontext ? - clone = InferenceContext(self.startingfrom, self.path) + clone = InferenceContext(self.path) clone.callcontext = self.callcontext clone.boundnode = self.boundnode return clone @@ -288,9 +287,9 @@ def path_wrapper(func): def wrapped(node, context=None, _func=func, **kwargs): """wrapper function handling context""" if context is None: - context = InferenceContext(node) + context = InferenceContext() context.push(node) - yielded = [] + yielded = set() try: for res in _func(node, context, **kwargs): # unproxy only true instance, not const, tuple, dict... @@ -300,11 +299,9 @@ def path_wrapper(func): ares = res if not ares in yielded: yield res - yielded.append(ares) - context.pop() - except: + yielded.add(ares) + finally: context.pop() - raise return wrapped def yes_if_nothing_infered(func): |