From 6ef9e233b4d9b43dc8327e8ff0121f323a74266a Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Mon, 22 Nov 2010 08:36:51 +0100 Subject: [PATCH] fix locals() in -3 mode --- Cython/Compiler/ExprNodes.py | 4 ++-- Cython/Compiler/ParseTreeTransforms.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index d44cfeb0..cb95f188 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -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 diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index f3dc0c9d..5ffc476f 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -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 -- 2.26.2