summaryrefslogtreecommitdiff
path: root/node_classes.py
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2011-01-11 16:41:26 +0100
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2011-01-11 16:41:26 +0100
commit0fa31cc5641f09fa42e8fed97cd7181333e9beac (patch)
tree751a7c37ce527399a4ba7fdb7c5bf656fa90db30 /node_classes.py
parent02e9e28c37cb57a8ea3abe6df11e3d5980cca922 (diff)
downloadastroid-0fa31cc5641f09fa42e8fed97cd7181333e9beac.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.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/node_classes.py b/node_classes.py
index 889479d..9bc6c56 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