summaryrefslogtreecommitdiff
path: root/scoped_nodes.py
diff options
context:
space:
mode:
authorEevee (Alex Munroe) <amunroe@yelp.com>2014-03-21 19:04:31 -0700
committerEevee (Alex Munroe) <amunroe@yelp.com>2014-07-01 17:33:00 -0700
commit2bf7e926b234bf8376a63f672380d2f1ae8eeb8d (patch)
tree9bf4dbeb167a4e12b94a551a1817fee8f927c6c7 /scoped_nodes.py
parenteb4cfdf7d5ab13616fda66c17ba3f822d7ef82ac (diff)
downloadastroid-git-2bf7e926b234bf8376a63f672380d2f1ae8eeb8d.tar.gz
Replace copy_context with some dynamic scoping.
Diffstat (limited to 'scoped_nodes.py')
-rw-r--r--scoped_nodes.py55
1 files changed, 29 insertions, 26 deletions
diff --git a/scoped_nodes.py b/scoped_nodes.py
index e354c5b8..a5bc37e9 100644
--- a/scoped_nodes.py
+++ b/scoped_nodes.py
@@ -39,7 +39,7 @@ from astroid.node_classes import Const, DelName, DelAttr, \
Dict, From, List, Pass, Raise, Return, Tuple, Yield, YieldFrom, \
LookupMixIn, const_factory as cf, unpack_infer, Name
from astroid.bases import NodeNG, InferenceContext, Instance,\
- YES, Generator, UnboundMethod, BoundMethod, _infer_stmts, copy_context, \
+ YES, Generator, UnboundMethod, BoundMethod, _infer_stmts, \
BUILTINS
from astroid.mixins import FilterStmtsMixin
from astroid.bases import Statement
@@ -308,12 +308,14 @@ class Module(LocalsDictNodeNG):
"""inferred getattr"""
# set lookup name since this is necessary to infer on import nodes for
# instance
- context = copy_context(context)
- context.lookupname = name
- try:
- return _infer_stmts(self.getattr(name, context), context, frame=self)
- except NotFoundError:
- raise InferenceError(name)
+ if not context:
+ context = InferenceContext()
+ with context.scope(lookupname=name):
+ try:
+ for infered in _infer_stmts(self.getattr(name, context), context, frame=self):
+ yield infered
+ except NotFoundError:
+ raise InferenceError(name)
def fully_defined(self):
"""return True if this module has been built from a .py file
@@ -993,27 +995,28 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
"""
# set lookup name since this is necessary to infer on import nodes for
# instance
- context = copy_context(context)
- context.lookupname = name
- try:
- for infered in _infer_stmts(self.getattr(name, context), context,
- frame=self):
- # yield YES object instead of descriptors when necessary
- if not isinstance(infered, Const) and isinstance(infered, Instance):
- try:
- infered._proxied.getattr('__get__', context)
- except NotFoundError:
- yield infered
+ if not context:
+ context = InferenceContext()
+ with context.scope(lookupname=name):
+ try:
+ for infered in _infer_stmts(self.getattr(name, context), context,
+ frame=self):
+ # yield YES object instead of descriptors when necessary
+ if not isinstance(infered, Const) and isinstance(infered, Instance):
+ try:
+ infered._proxied.getattr('__get__', context)
+ except NotFoundError:
+ yield infered
+ else:
+ yield YES
else:
- yield YES
+ yield function_to_method(infered, self)
+ except NotFoundError:
+ if not name.startswith('__') and self.has_dynamic_getattr(context):
+ # class handle some dynamic attributes, return a YES object
+ yield YES
else:
- yield function_to_method(infered, self)
- except NotFoundError:
- if not name.startswith('__') and self.has_dynamic_getattr(context):
- # class handle some dynamic attributes, return a YES object
- yield YES
- else:
- raise InferenceError(name)
+ raise InferenceError(name)
def has_dynamic_getattr(self, context=None):
"""return True if the class has a custom __getattr__ or