From 30cf86bc0ce6a7ab1c281f373c91ae471f975dd6 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 16 Dec 2010 20:46:07 +0100 Subject: [PATCH] fix ticket #576: builtin 'str' type must be 'unicode' type in -3 mode --- Cython/Compiler/Symtab.py | 13 +++++++++++++ tests/run/cython3.pyx | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 4573b3c3..c8683499 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -733,6 +733,13 @@ class BuiltinScope(Scope): cname, type = definition self.declare_var(name, type, None, cname) + def lookup(self, name, language_level=None): + # 'language_level' is passed by ModuleScope + if language_level == 3: + if name == 'str': + name = 'unicode' + return Scope.lookup(self, name) + def declare_builtin(self, name, pos): if not hasattr(builtins, name): if self.outer_scope is not None: @@ -882,6 +889,12 @@ class ModuleScope(Scope): def global_scope(self): return self + def lookup(self, name): + entry = self.lookup_here(name) + if entry is not None: + return entry + return self.outer_scope.lookup(name, language_level = self.context.language_level) + def declare_builtin(self, name, pos): if not hasattr(builtins, name) and name != 'xrange': # 'xrange' is special cased in Code.py diff --git a/tests/run/cython3.pyx b/tests/run/cython3.pyx index 0d10bdbd..d3f416e8 100644 --- a/tests/run/cython3.pyx +++ b/tests/run/cython3.pyx @@ -66,6 +66,19 @@ def unicode_literals(): print(isinstance(ustring, unicode) or type(ustring)) return ustring +def str_type_is_unicode(): + """ + >>> str_type, s = str_type_is_unicode() + >>> isinstance(s, type(ustring)) or (s, str_type) + True + >>> isinstance(s, str_type) or (s, str_type) + True + >>> isinstance(ustring, str_type) or str_type + True + """ + cdef str s = 'abc' + return str, s + def list_comp(): """ >>> list_comp() -- 2.26.2