Issue #1309 new

Python-3.4 - patch - unrepr does not recognize 'NameConstant'

Artyom Lebedev
created an issue

Tried cherrypy with recently released Python-3.4. So far the only problem was configuration parsing problem. unrepr() method uses ast module which has changed semantic for named constants. Now the corresponding class called NameConstant instead of Name and has 'value' attribute with Python value instead of 'id' attribute with name.

The thrown exception:

Traceback (most recent call last):
  File "<my_prefix>/python/cherrypy/lib/", line 215, in as_dict
    value = unrepr(value)
  File "<my_prefix>/python/cherrypy/lib/", line 453, in unrepr
  File "<my_prefix>/python/cherrypy/lib/", line 338, in build
TypeError: unrepr does not recognize 'NameConstant'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 10, in <module>
  File "", line 204, in Main
    cherrypy.config.update(os.path.join(configDir, 'server.conf'))
  File "<my_prefix>/python/cherrypy/", line 156, in update
    reprconf.Config.update(self, config)
  File "<my_prefix>/python/cherrypy/lib/", line 158, in update
    config = Parser().dict_from_file(config)
  File "<my_prefix>/python/cherrypy/lib/", line 230, in dict_from_file
    return self.as_dict()
  File "<my_prefix>/python/cherrypy/lib/", line 221, in as_dict
    raise ValueError(msg, x.__class__.__name__, x.args)
ValueError: ("Config error in section: 'global', option: 'log.screen', value: 'True'. Config values must be valid Python.", 'TypeError', ("unrepr does not recognize 'NameConstant'",))

The proposed patch (should be reviewed, I did not dive into idea with modules in the current solution):

diff --git a/lib/ b/lib/
index 83ca78f..de00466 100644
--- a/lib/
+++ b/lib/
@@ -415,6 +415,9 @@

         raise TypeError("unrepr could not resolve the name %s" % repr(name))

+    def build_NameConstant(self, o):
+        return o.value
     def build_UnaryOp(self, o):
         op, operand = map(, [o.op, o.operand])
         return op(operand)

Comments (0)

  1. Log in to comment