Commit 30cf86bc authored by Stefan Behnel's avatar Stefan Behnel

fix ticket #576: builtin 'str' type must be 'unicode' type in -3 mode

parent 4d98733e
......@@ -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
......
......@@ -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()
......
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