make sure Python strings (and other Python literals) do not loose their type during...
authorStefan Behnel <scoder@users.berlios.de>
Sat, 12 Sep 2009 11:54:21 +0000 (13:54 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sat, 12 Sep 2009 11:54:21 +0000 (13:54 +0200)
Cython/Compiler/ExprNodes.py

index 216464555657c8bcdff9873fe2697decd0da7d7b..731d4ecaecd12ad8931ffb9b8b5f1ea1e89eb5bf 100644 (file)
@@ -579,12 +579,13 @@ class PyConstNode(AtomicExprNode):
     #  Abstract base class for constant Python values.
     
     is_literal = 1
+    type = py_object_type
     
     def is_simple(self):
         return 1
     
     def analyse_types(self, env):
-        self.type = py_object_type
+        pass
     
     def calculate_result_code(self):
         return self.value
@@ -791,7 +792,11 @@ class StringNode(ConstNode):
     def as_py_string_node(self, env):
         # Return a new StringNode with the same value as this node
         # but whose type is a Python type instead of a C type.
-        return StringNode(self.pos, value = self.value, type = py_object_type)
+        if self.value.encoding is None:
+            py_type = Builtin.unicode_type
+        else:
+            py_type = Builtin.bytes_type
+        return StringNode(self.pos, value = self.value, type = py_type)
 
     def generate_evaluation_code(self, code):
         if self.type.is_pyobject: