1.1 --- a/generator.py Fri Nov 18 16:47:07 2016 +0100
1.2 +++ b/generator.py Fri Nov 18 17:25:24 2016 +0100
1.3 @@ -369,8 +369,9 @@
1.4
1.5 # NOTE: This makes assumptions about the __builtins__ structure.
1.6
1.7 - typename = value.__class__.__name__
1.8 - ref = Reference("<instance>", "__builtins__.%s.%s" % (typename, typename))
1.9 + modname = value.__class__.__name__
1.10 + typename = modname == "str" and "string" or modname
1.11 + ref = Reference("<instance>", "__builtins__.%s.%s" % (modname, typename))
1.12
1.13 self.make_constant(f_decls, f_defs, ref, const_path, structure_name, value)
1.14
2.1 --- a/inspector.py Fri Nov 18 16:47:07 2016 +0100
2.2 +++ b/inspector.py Fri Nov 18 17:25:24 2016 +0100
2.3 @@ -70,8 +70,8 @@
2.4
2.5 # Detect and record imports and globals declared in the module.
2.6
2.7 - self.assign_general_local("__name__", self.get_constant("str", self.name))
2.8 - self.assign_general_local("__file__", self.get_constant("str", filename))
2.9 + self.assign_general_local("__name__", self.get_constant("string", self.name))
2.10 + self.assign_general_local("__file__", self.get_constant("string", filename))
2.11 self.process_structure(self.astnode)
2.12
2.13 # Set the class of the module after the definition has occurred.
2.14 @@ -291,7 +291,8 @@
2.15 # Constant usage.
2.16
2.17 elif isinstance(n, compiler.ast.Const):
2.18 - return self.get_literal_instance(n, n.value.__class__.__name__)
2.19 + typename = n.value.__class__.__name__
2.20 + return self.get_literal_instance(n, typename == "str" and "string" or typename)
2.21
2.22 elif isinstance(n, compiler.ast.Dict):
2.23 return self.get_literal_instance(n, "dict")
2.24 @@ -527,7 +528,7 @@
2.25 self.set_name("__fn__") # special instantiator attribute
2.26 self.set_name("__args__") # special instantiator attribute
2.27
2.28 - self.assign_general_local("__name__", self.get_constant("str", class_name))
2.29 + self.assign_general_local("__name__", self.get_constant("string", class_name))
2.30 self.process_structure_node(n.code)
2.31 self.exit_namespace()
2.32 self.in_class = in_class
3.1 --- a/lib/__builtins__/__init__.py Fri Nov 18 16:47:07 2016 +0100
3.2 +++ b/lib/__builtins__/__init__.py Fri Nov 18 17:25:24 2016 +0100
3.3 @@ -87,7 +87,7 @@
3.4 from __builtins__.none import None, NoneType
3.5 from __builtins__.notimplemented import NotImplemented, NotImplementedType
3.6 from __builtins__.set import frozenset, set
3.7 -from __builtins__.str import basestring, str, unicode
3.8 +from __builtins__.str import basestring, str, string, unicode
3.9 from __builtins__.tuple import tuple
3.10
3.11 # Functions.
4.1 --- a/lib/__builtins__/str.py Fri Nov 18 16:47:07 2016 +0100
4.2 +++ b/lib/__builtins__/str.py Fri Nov 18 17:25:24 2016 +0100
4.3 @@ -74,7 +74,8 @@
4.4 def __len__(self):
4.5 return native._str_len(self)
4.6
4.7 - def __str__(self): pass
4.8 + def __str__(self):
4.9 + return self
4.10
4.11 def __bool__(self):
4.12 return native._str_nonempty(self)
4.13 @@ -101,10 +102,16 @@
4.14
4.15 return listiterator(self)
4.16
4.17 -class str(basestring):
4.18 +class string(basestring):
4.19 pass
4.20
4.21 class unicode(basestring):
4.22 def encode(self, encoding): pass
4.23
4.24 +def str(obj):
4.25 +
4.26 + "Return the string representation of 'obj'."
4.27 +
4.28 + return obj.__str__()
4.29 +
4.30 # vim: tabstop=4 expandtab shiftwidth=4
5.1 --- a/modules.py Fri Nov 18 16:47:07 2016 +0100
5.2 +++ b/modules.py Fri Nov 18 17:25:24 2016 +0100
5.3 @@ -299,10 +299,12 @@
5.4
5.5 # NOTE: This makes assumptions about the __builtins__ structure.
5.6
5.7 - module_name = "__builtins__.%s" % name
5.8 + modname = name == "string" and "str" or name
5.9 +
5.10 + module_name = "__builtins__.%s" % modname
5.11 if self.name != module_name:
5.12 self.queue_module(module_name, True)
5.13 - return Reference("<class>", "__builtins__.%s.%s" % (name, name))
5.14 + return Reference("<class>", "__builtins__.%s.%s" % (modname, name))
5.15
5.16 def get_object(self, path, defer=True):
5.17
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/tests/print.py Fri Nov 18 17:25:24 2016 +0100
6.3 @@ -0,0 +1,1 @@
6.4 +print "Hello!"