diff options
author | Emile Anclin <emile.anclin@logilab.fr> | 2010-02-17 09:22:09 +0100 |
---|---|---|
committer | Emile Anclin <emile.anclin@logilab.fr> | 2010-02-17 09:22:09 +0100 |
commit | 799a6102edc88757ee0e35dbfc8db32bac67ad59 (patch) | |
tree | d5e9ebf535aaf154d59766cdabf2986682d3d90b | |
parent | 5dce31bcbdfedf8b82823ee897b815865e63c38a (diff) | |
download | astroid-git-799a6102edc88757ee0e35dbfc8db32bac67ad59.tar.gz |
update scoped_nodes.py from default/stable branches
--HG--
branch : rebuild
-rw-r--r-- | scoped_nodes.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/scoped_nodes.py b/scoped_nodes.py index 278b7ca8..744a2e3e 100644 --- a/scoped_nodes.py +++ b/scoped_nodes.py @@ -41,7 +41,7 @@ from logilab.astng.node_classes import (Const, Comprehension, Dict, are_exclusive, const_factory as cf, unpack_infer) from logilab.astng._nodes import NodeNG, StmtMixIn, BaseClass from logilab.astng.infutils import YES, InferenceContext, Instance, Generator, \ - UnboundMethod, _infer_stmts, copy_context + UnboundMethod, BoundMethod, _infer_stmts, copy_context from logilab.astng.nodes_as_string import as_string @@ -54,12 +54,14 @@ def remove_nodes(func, cls): return nodes return wrapper -def function_to_unbound_method(func): - def wrapper(*args, **kwargs): - return [isinstance(n, Function) and UnboundMethod(n) or n - for n in func(*args, **kwargs)] - return wrapper +def function_to_method(n, klass): + if isinstance(n, Function): + if n.type == 'classmethod': + return BoundMethod(n, klass) + if n.type != 'staticmethod': + return UnboundMethod(n) + return n def std_special_attributes(self, name, add_locals=True): if add_locals: @@ -422,6 +424,9 @@ class Module(LocalsDictNodeNG): def pytype(self): return '__builtin__.module' + def display_type(self): + return 'Module' + def getattr(self, name, context=None): if not name in self.special_attributes: try: @@ -574,6 +579,11 @@ class Lambda(LocalsDictNodeNG): return '__builtin__.instancemethod' return '__builtin__.function' + def display_type(self): + if 'method' in self.type: + return 'Method' + return 'Function' + def callable(self): return True @@ -826,6 +836,9 @@ class Class(StmtMixIn, LocalsDictNodeNG): return '__builtin__.type' return '__builtin__.classobj' + def display_type(self): + return 'Class' + def callable(self): return True @@ -958,7 +971,6 @@ class Class(StmtMixIn, LocalsDictNodeNG): if not values: raise NotFoundError(name) return values - getattr = function_to_unbound_method(remove_nodes(getattr, DelAttr)) def igetattr(self, name, context=None): """inferred getattr, need special treatment in class to handle @@ -980,7 +992,7 @@ class Class(StmtMixIn, LocalsDictNodeNG): else: yield YES else: - yield infered + 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 |