# HG changeset patch # User Paul Boddie # Date 1479486324 -3600 # Node ID c0775a0f068c80dfad141db0dd21246120de1220 # Parent b062edfbeaab6e1b70fff0a29b78a1e6db5be6bf Made str a function, introducing a separate string class. diff -r b062edfbeaab -r c0775a0f068c generator.py --- a/generator.py Fri Nov 18 16:47:07 2016 +0100 +++ b/generator.py Fri Nov 18 17:25:24 2016 +0100 @@ -369,8 +369,9 @@ # NOTE: This makes assumptions about the __builtins__ structure. - typename = value.__class__.__name__ - ref = Reference("", "__builtins__.%s.%s" % (typename, typename)) + modname = value.__class__.__name__ + typename = modname == "str" and "string" or modname + ref = Reference("", "__builtins__.%s.%s" % (modname, typename)) self.make_constant(f_decls, f_defs, ref, const_path, structure_name, value) diff -r b062edfbeaab -r c0775a0f068c inspector.py --- a/inspector.py Fri Nov 18 16:47:07 2016 +0100 +++ b/inspector.py Fri Nov 18 17:25:24 2016 +0100 @@ -70,8 +70,8 @@ # Detect and record imports and globals declared in the module. - self.assign_general_local("__name__", self.get_constant("str", self.name)) - self.assign_general_local("__file__", self.get_constant("str", filename)) + self.assign_general_local("__name__", self.get_constant("string", self.name)) + self.assign_general_local("__file__", self.get_constant("string", filename)) self.process_structure(self.astnode) # Set the class of the module after the definition has occurred. @@ -291,7 +291,8 @@ # Constant usage. elif isinstance(n, compiler.ast.Const): - return self.get_literal_instance(n, n.value.__class__.__name__) + typename = n.value.__class__.__name__ + return self.get_literal_instance(n, typename == "str" and "string" or typename) elif isinstance(n, compiler.ast.Dict): return self.get_literal_instance(n, "dict") @@ -527,7 +528,7 @@ self.set_name("__fn__") # special instantiator attribute self.set_name("__args__") # special instantiator attribute - self.assign_general_local("__name__", self.get_constant("str", class_name)) + self.assign_general_local("__name__", self.get_constant("string", class_name)) self.process_structure_node(n.code) self.exit_namespace() self.in_class = in_class diff -r b062edfbeaab -r c0775a0f068c lib/__builtins__/__init__.py --- a/lib/__builtins__/__init__.py Fri Nov 18 16:47:07 2016 +0100 +++ b/lib/__builtins__/__init__.py Fri Nov 18 17:25:24 2016 +0100 @@ -87,7 +87,7 @@ from __builtins__.none import None, NoneType from __builtins__.notimplemented import NotImplemented, NotImplementedType from __builtins__.set import frozenset, set -from __builtins__.str import basestring, str, unicode +from __builtins__.str import basestring, str, string, unicode from __builtins__.tuple import tuple # Functions. diff -r b062edfbeaab -r c0775a0f068c lib/__builtins__/str.py --- a/lib/__builtins__/str.py Fri Nov 18 16:47:07 2016 +0100 +++ b/lib/__builtins__/str.py Fri Nov 18 17:25:24 2016 +0100 @@ -74,7 +74,8 @@ def __len__(self): return native._str_len(self) - def __str__(self): pass + def __str__(self): + return self def __bool__(self): return native._str_nonempty(self) @@ -101,10 +102,16 @@ return listiterator(self) -class str(basestring): +class string(basestring): pass class unicode(basestring): def encode(self, encoding): pass +def str(obj): + + "Return the string representation of 'obj'." + + return obj.__str__() + # vim: tabstop=4 expandtab shiftwidth=4 diff -r b062edfbeaab -r c0775a0f068c modules.py --- a/modules.py Fri Nov 18 16:47:07 2016 +0100 +++ b/modules.py Fri Nov 18 17:25:24 2016 +0100 @@ -299,10 +299,12 @@ # NOTE: This makes assumptions about the __builtins__ structure. - module_name = "__builtins__.%s" % name + modname = name == "string" and "str" or name + + module_name = "__builtins__.%s" % modname if self.name != module_name: self.queue_module(module_name, True) - return Reference("", "__builtins__.%s.%s" % (name, name)) + return Reference("", "__builtins__.%s.%s" % (modname, name)) def get_object(self, path, defer=True): diff -r b062edfbeaab -r c0775a0f068c tests/print.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/print.py Fri Nov 18 17:25:24 2016 +0100 @@ -0,0 +1,1 @@ +print "Hello!"