don't call const_factory for builtin types subclasses, this will trigger error later. Closes #124337

authorSylvain Th?nault <sylvain.thenault@logilab.fr>
changeset78a891b175ca
branchstable
phasedraft
hiddenyes
parent revision#650d727f2f1c enhanced generator support. Closes #124340
child revision#51676b3d4603 reintroduce spaces necessary for test_module_as_string
files modified by this revision
node_classes.py
raw_building.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1364454788 -3600
# Thu Mar 28 08:13:08 2013 +0100
# Branch stable
# Node ID 78a891b175ca61ec07b835d3b043a3b4a4dc6dd5
# Parent 650d727f2f1c3deae9f9a0f25b3a67616819bbb7
don't call const_factory for builtin types subclasses, this will trigger error later. Closes #124337

diff --git a/node_classes.py b/node_classes.py
@@ -891,20 +891,21 @@
1          CONST_CLS[kls] = Const
2  _update_const_classes()
3 
4  def const_factory(value):
5      """return an astng node for a python value"""
6 -    # since const_factory is called to evaluate content of container (eg list,
7 -    # tuple), it may be called with some node as argument that should be left
8 -    # untouched
9 +    # XXX we should probably be stricter here and only consider stuff in
10 +    # CONST_CLS or do better treatment:
11 +    #
12 +    # * shall we really support nodes as argument? if so, detail cases where
13 +    # * this may occurs
14 +    #
15 +    # * in case where value is not in CONST_CLS, we should rather recall the
16 +    #   builder on this value than returning an empty node
17      if isinstance(value, NodeNG):
18          return value
19      try:
20          return CONST_CLS[value.__class__](value)
21      except (KeyError, AttributeError):
22 -        # some constants (like from gtk._gtk) don't have their class in
23 -        # CONST_CLS, though we can "assert isinstance(value, tuple(CONST_CLS))"
24 -        if isinstance(value, tuple(CONST_CLS)):
25 -            return Const(value)
26          node = EmptyNode()
27          node.object = value
28          return node
diff --git a/raw_building.py b/raw_building.py
@@ -275,11 +275,11 @@
29                  assert isinstance(member, object)
30                  object_build_methoddescriptor(node, member, name)
31              elif isdatadescriptor(member):
32                  assert isinstance(member, object)
33                  object_build_datadescriptor(node, member, name)
34 -            elif isinstance(member, _CONSTANTS):
35 +            elif type(member) in _CONSTANTS:
36                  attach_const_node(node, name, member)
37              else:
38                  # create an empty node so that the name is actually defined
39                  attach_dummy_node(node, name, member)
40