diff options
-rw-r--r-- | inference.py | 5 | ||||
-rw-r--r-- | nodes.py | 22 | ||||
-rw-r--r-- | protocols.py | 4 |
3 files changed, 22 insertions, 9 deletions
diff --git a/inference.py b/inference.py index 3e791e9b..df01e837 100644 --- a/inference.py +++ b/inference.py @@ -162,10 +162,13 @@ 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__) -nodes.Node.infer = infer_default +for cls in nodes.ALL_NODES: + cls.infer = infer_default def infer_end(self, context=None): @@ -121,6 +121,16 @@ With._astng_fields = ('expr', 'vars', 'body') While._astng_fields = ('test', 'body', 'orelse',) Yield._astng_fields = ('value',) +STMTS_NODES = (Assign, AugAssign, Assert, Break, Class, Continue, Delete, + Discard, ExceptHandler, Exec, For, From, Function, Global, If, + Import, Pass, Print, Raise, Return, TryExcept, TryFinally, While, + With, Yield) + +ALL_NODES = STMTS_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) # Node ###################################################################### @@ -323,6 +333,9 @@ class NodeNG: return name return None + def callable(self): + return False + def eq(self, value): return False @@ -336,7 +349,10 @@ class NodeNG: _repr_tree(self, result) print "\n".join(result) -extend_class(Node, NodeNG) +# extend all classes instead of base Node class which is an unextendable type +# in 2.6 +for cls in ALL_NODES: + extend_class(cls, NodeNG) INDENT = " " @@ -376,9 +392,7 @@ def replace_child(self, child, newchild): child.parent = None sequence[sequence.index(child)] = newchild -for klass in (Assign, AugAssign, Assert, Break, Class, Continue, Delete, Discard, - ExceptHandler, Exec, For, From, Function, Global, If, Import, Pass, - Print, Raise, Return, TryExcept, TryFinally, While, With, Yield): +for klass in STMT_NODES: klass.is_statement = True klass.replace = replace_child Module.replace = replace_child diff --git a/protocols.py b/protocols.py index 070b0069..8385c666 100644 --- a/protocols.py +++ b/protocols.py @@ -333,10 +333,6 @@ nodes.With.ass_type = end_ass_type # callable protocol ########################################################### -def callable_default(self): - return False -nodes.Node.callable = callable_default - def callable_true(self): return True |