From 25b78a7a6a8d52fd0a37fd0330acfab993e2ac8f Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 9 Nov 2013 14:57:57 +0100 Subject: [PATCH] implement minor special case of indexing into an inferred 1-char Unicode string --HG-- extra : amend_source : 068dca3eae20906b495571f1d80548dc5f99ed51 --- Cython/Compiler/ExprNodes.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index c041053..3d91371 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -3011,15 +3011,16 @@ class IndexNode(ExprNode): if base_type.is_unicode_char: # we infer Py_UNICODE/Py_UCS4 for unicode strings in some # cases, but indexing must still work for them - if self.index.constant_result in (0, -1): - # FIXME: we know that this node is redundant - - # currently, this needs to get handled in Optimize.py - pass + if setting: + warning(self.pos, "cannot assign to Unicode string index", level=1) + elif self.index.constant_result in (0, -1): + # uchar[0] => uchar + return self.base self.base = self.base.coerce_to_pyobject(env) base_type = self.base.type if base_type.is_pyobject: if self.index.type.is_int: - if (not setting + if (getting and (base_type in (list_type, tuple_type, bytearray_type)) and (not self.index.type.signed or not env.directives['wraparound'] -- 2.7.4