diff options
author | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2011-01-11 16:41:26 +0100 |
---|---|---|
committer | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2011-01-11 16:41:26 +0100 |
commit | bc29458ac9e5be50f71d95aba725a15ce78b7887 (patch) | |
tree | aac334f3178347fbc12c3fd1af85aae848869624 /node_classes.py | |
parent | 097d291e6ac3b9f08f947f6b9e84079b8f6a0d96 (diff) | |
download | astroid-git-bc29458ac9e5be50f71d95aba725a15ce78b7887.tar.gz |
fix constant_factory, it may be given unknown object when building from living objects
Diffstat (limited to 'node_classes.py')
-rw-r--r-- | node_classes.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/node_classes.py b/node_classes.py index 889479d0..9bc6c568 100644 --- a/node_classes.py +++ b/node_classes.py @@ -694,7 +694,6 @@ class Print(Statement): values = None - class Raise(Statement): """class representing a Raise node""" exc = None @@ -886,10 +885,13 @@ _update_const_classes() def const_factory(value): """return an astng node for a python value""" - # /!\ current implementation expects the item / elts nodes for - # dict, list, tuples and the constant value for the others. - # - # some constants (like from gtk._gtk) don't have their class in CONST_CLS, - # even though we can "assert isinstance(value, tuple(CONST_CLS))" - return CONST_CLS.get(value.__class__, Const)(value) - + try: + return CONST_CLS[value.__class__](value) + except (KeyError, AttributeError): + # some constants (like from gtk._gtk) don't have their class in + # CONST_CLS, though we can "assert isinstance(value, tuple(CONST_CLS))" + if isinstance(value, tuple(CONST_CLS)): + return Const(value) + node = EmptyNode() + node.object = value + return None |