diff options
| author | Emile Anclin <emile.anclin@logilab.fr> | 2009-11-25 16:55:08 +0100 |
|---|---|---|
| committer | Emile Anclin <emile.anclin@logilab.fr> | 2009-11-25 16:55:08 +0100 |
| commit | 0e0a115601ebbbaace352003299573450a4f1b31 (patch) | |
| tree | b89bc25152be484c72a23f7ff65c1fdfe6455cfa | |
| parent | 1b6a9dd4fb30e429a75dfe4c7d0c9b8ac7904176 (diff) | |
| download | astroid-git-0e0a115601ebbbaace352003299573450a4f1b31.tar.gz | |
move default infer method to NodeNg
--HG--
branch : rebuild
| -rw-r--r-- | _nodes.py | 46 | ||||
| -rw-r--r-- | inference.py | 8 |
2 files changed, 6 insertions, 48 deletions
@@ -31,21 +31,6 @@ except ImportError: AST_MODE = 'compiler' from logilab.astng.utils import REDIRECT -LOOP_SCOPES = (Comprehension, For,) - - -STMT_NODES = ( - Assert, Assign, AugAssign, Break, Class, Continue, Delete, Discard, - ExceptHandler, Exec, For, From, Function, Global, If, Import, Pass, Print, - Raise, Return, TryExcept, TryFinally, While, With - ) - -ALL_NODES = STMT_NODES + ( - Arguments, AssAttr, AssName, BinOp, BoolOp, Backquote, CallFunc, Compare, - Comprehension, Const, Decorators, DelAttr, DelName, Dict, Ellipsis, - EmptyNode, ExtSlice, Getattr, GenExpr, IfExp, Index, Keyword, Lambda, - List, ListComp, Module, Name, Slice, Subscript, UnaryOp, Tuple, Yield - ) # Node ###################################################################### @@ -221,9 +206,14 @@ class NodeNG(BaseClass): yield matching def _infer_name(self, frame, name): - # overriden for From, Import, Global, TryExcept and Arguments + # overridden for From, Import, Global, TryExcept and Arguments return None + def infer(self, context=None): + """we don't know how to resolve a statement by default""" + # this method is overridden by most concrete classes + raise InferenceError(self.__class__.__name__) + def callable(self): return False @@ -328,28 +318,4 @@ class BlockRangeMixIn(BaseClass): return lineno, last or self.tolineno -# constants ... ############################################################## - -CONST_CLS = { - list: List, - tuple: Tuple, - dict: Dict, - } - -def const_factory(value): - """return an astng node for a python value""" - try: - # if value is of class list, tuple, dict use specific class, not Const - cls = CONST_CLS[value.__class__] - node = cls() - if isinstance(node, Dict): - node.items = () - else: - node.elts = () - except KeyError: - try: - node = Const(value) - except KeyError: - node = _const_factory(value) - return node diff --git a/inference.py b/inference.py index a136a58d..d8f67c97 100644 --- a/inference.py +++ b/inference.py @@ -152,14 +152,6 @@ class CallContext: # .infer method ############################################################### -# extend all classes instead of base Node class which is an unextendable type -# in 2.6 -def infer_default(self, context=None): - """we don't know how to resolve a statement by default""" - raise InferenceError(self.__class__.__name__) -for cls in nodes.ALL_NODES: - cls.infer = infer_default - def infer_end(self, context=None): """inference's end for node such as Module, Class, Function, Const... |
