fix locals() in -3 mode
authorStefan Behnel <scoder@users.berlios.de>
Mon, 22 Nov 2010 07:36:51 +0000 (08:36 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Mon, 22 Nov 2010 07:36:51 +0000 (08:36 +0100)
Cython/Compiler/ExprNodes.py
Cython/Compiler/ParseTreeTransforms.py

index d44cfeb08148cb736b2723661d4056ee3eeea5df..cb95f18822e1b7fefa7169df0a38b15ef4055ee2 100755 (executable)
@@ -1094,11 +1094,11 @@ class StringNode(PyConstNode):
             self.check_for_coercion_error(dst_type, fail=True)
 
         # this will be a unicode string in Py3, so make sure we can decode it
-        if self.value.encoding:
+        if self.value.encoding and self.unicode_value is None:
             encoding = self.value.encoding
             try:
                 self.value.decode(encoding)
-            except UnicodeDecodeError:
+            except (UnicodeDecodeError, AttributeError):
                 error(self.pos, "String decoding as '%s' failed. Consider using a byte string or unicode string explicitly, or adjust the source code encoding." % encoding)
 
         return self
index f3dc0c9debf87a2318af0f84fc66fbeca2a1527c..5ffc476fddf6f021d7184c31b3168184599ed6b9 100644 (file)
@@ -1448,9 +1448,10 @@ class TransformBuiltinMethods(EnvTransform):
                     error(self.pos, "Builtin 'locals()' called with wrong number of args, expected 0, got %d" % len(node.args))
                     return node
                 pos = node.pos
-                items = [ExprNodes.DictItemNode(pos, 
-                                                key=ExprNodes.StringNode(pos, value=var),
-                                                value=ExprNodes.NameNode(pos, name=var)) for var in lenv.entries]
+                items = [ ExprNodes.DictItemNode(pos, 
+                                                 key=ExprNodes.StringNode(pos, value=var, unicode_value=var),
+                                                 value=ExprNodes.NameNode(pos, name=var))
+                          for var in lenv.entries ]
                 return ExprNodes.DictNode(pos, key_value_pairs=items)
 
         # cython.foo