Commit 6ef9e233 authored by Stefan Behnel's avatar Stefan Behnel

fix locals() in -3 mode

parent 39570c69
...@@ -1094,11 +1094,11 @@ class StringNode(PyConstNode): ...@@ -1094,11 +1094,11 @@ class StringNode(PyConstNode):
self.check_for_coercion_error(dst_type, fail=True) self.check_for_coercion_error(dst_type, fail=True)
# this will be a unicode string in Py3, so make sure we can decode it # 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 encoding = self.value.encoding
try: try:
self.value.decode(encoding) 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) 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 return self
......
...@@ -1448,9 +1448,10 @@ class TransformBuiltinMethods(EnvTransform): ...@@ -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)) error(self.pos, "Builtin 'locals()' called with wrong number of args, expected 0, got %d" % len(node.args))
return node return node
pos = node.pos pos = node.pos
items = [ExprNodes.DictItemNode(pos, items = [ ExprNodes.DictItemNode(pos,
key=ExprNodes.StringNode(pos, value=var), key=ExprNodes.StringNode(pos, value=var, unicode_value=var),
value=ExprNodes.NameNode(pos, name=var)) for var in lenv.entries] value=ExprNodes.NameNode(pos, name=var))
for var in lenv.entries ]
return ExprNodes.DictNode(pos, key_value_pairs=items) return ExprNodes.DictNode(pos, key_value_pairs=items)
# cython.foo # cython.foo
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment