1.1 --- a/common.py Tue Jun 29 22:41:05 2021 +0200
1.2 +++ b/common.py Tue Jun 29 23:50:13 2021 +0200
1.3 @@ -1594,9 +1594,7 @@
1.4
1.5 "Return the module name containing the given type 'name'."
1.6
1.7 - if name == "string":
1.8 - modname = "str"
1.9 - elif name == "NoneType":
1.10 + if name == "NoneType":
1.11 modname = "none"
1.12 else:
1.13 modname = name
1.14 @@ -1607,10 +1605,7 @@
1.15
1.16 "Return the type name provided by the given Python value 'name'."
1.17
1.18 - if name == "str":
1.19 - return "string"
1.20 - else:
1.21 - return name
1.22 + return name
1.23
1.24 def get_builtin_class(name):
1.25
2.1 --- a/generator.py Tue Jun 29 22:41:05 2021 +0200
2.2 +++ b/generator.py Tue Jun 29 23:50:13 2021 +0200
2.3 @@ -46,7 +46,7 @@
2.4 int_type = "__builtins__.int.int"
2.5 list_type = "__builtins__.list.list"
2.6 none_type = "__builtins__.none.NoneType"
2.7 - string_type = "__builtins__.str.string"
2.8 + string_type = "__builtins__.str.str"
2.9 tuple_type = "__builtins__.tuple.tuple"
2.10 type_type = "__builtins__.core.type"
2.11 unicode_type = "__builtins__.unicode.unicode"
2.12 @@ -1215,6 +1215,21 @@
2.13 encode_instantiator_pointer(path),
2.14 )
2.15
2.16 + # Special-case the string types.
2.17 +
2.18 + # Here, the __builtins__.str.new_str function is called with the
2.19 + # initialiser's parameter.
2.20 +
2.21 + elif path == self.string_type:
2.22 + print >>f_code, """\
2.23 +__attr %s(__attr __self, __attr obj)
2.24 +{
2.25 + return __fn___builtins___str_new_str(__NULL, obj);
2.26 +}
2.27 +""" % (
2.28 + encode_instantiator_pointer(path),
2.29 + )
2.30 +
2.31 # Generic instantiation support.
2.32
2.33 else:
2.34 @@ -1285,6 +1300,6 @@
2.35
2.36 return 0;
2.37 }
2.38 -""" % encode_function_pointer("__builtins__.str.str")
2.39 +""" % encode_instantiator_pointer("__builtins__.str.str")
2.40
2.41 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/inspector.py Tue Jun 29 22:41:05 2021 +0200
3.2 +++ b/inspector.py Tue Jun 29 23:50:13 2021 +0200
3.3 @@ -3,8 +3,7 @@
3.4 """
3.5 Inspect and obtain module structure.
3.6
3.7 -Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
3.8 - 2018, 2019 Paul Boddie <paul@boddie.org.uk>
3.9 +Copyright (C) 2007-2019, 2021 Paul Boddie <paul@boddie.org.uk>
3.10
3.11 This program is free software; you can redistribute it and/or modify it under
3.12 the terms of the GNU General Public License as published by the Free Software
3.13 @@ -78,13 +77,13 @@
3.14
3.15 ref = self.get_builtin("module")
3.16 self.set_name("__class__", ref)
3.17 - self.set_name("__name__", self.get_constant("string", self.name).reference())
3.18 - self.set_name("__file__", self.get_constant("string", filename).reference())
3.19 + self.set_name("__name__", self.get_constant("str", self.name).reference())
3.20 + self.set_name("__file__", self.get_constant("str", filename).reference())
3.21
3.22 # Reserve a constant for the encoding.
3.23
3.24 if self.encoding:
3.25 - self.get_constant("string", self.encoding)
3.26 + self.get_constant("str", self.encoding)
3.27
3.28 # Get module-level attribute usage details.
3.29
3.30 @@ -531,7 +530,7 @@
3.31 # Provide leafname, parent and context attributes.
3.32
3.33 parent, leafname = class_name.rsplit(".", 1)
3.34 - self.set_name("__name__", self.get_constant("string", leafname).reference())
3.35 + self.set_name("__name__", self.get_constant("str", leafname).reference())
3.36
3.37 if class_name != "__builtins__.core.function":
3.38 self.set_name("__parent__")
3.39 @@ -681,7 +680,7 @@
3.40
3.41 # Define a leafname attribute value for the function instance.
3.42
3.43 - ref = self.get_builtin_class("string")
3.44 + ref = self.get_builtin_class("str")
3.45 self.reserve_constant(function_name, name, ref.get_origin())
3.46
3.47 # Track attribute usage within the namespace.
4.1 --- a/lib/__builtins__/__init__.py Tue Jun 29 22:41:05 2021 +0200
4.2 +++ b/lib/__builtins__/__init__.py Tue Jun 29 23:50:13 2021 +0200
4.3 @@ -68,7 +68,7 @@
4.4 from __builtins__.none import None, NoneType
4.5 from __builtins__.notimplemented import NotImplemented, NotImplementedType
4.6 from __builtins__.set import frozenset, set
4.7 -from __builtins__.str import basestring, str, string
4.8 +from __builtins__.str import basestring, str
4.9 from __builtins__.tuple import tuple
4.10 from __builtins__.unicode import unicode
4.11
5.1 --- a/lib/__builtins__/buffer.py Tue Jun 29 22:41:05 2021 +0200
5.2 +++ b/lib/__builtins__/buffer.py Tue Jun 29 23:50:13 2021 +0200
5.3 @@ -53,7 +53,7 @@
5.4
5.5 if isinstance(s, buffer):
5.6 list_concat(self, s.__data__)
5.7 - elif isinstance(s, string):
5.8 + elif isinstance(s, str):
5.9 list_append(self, s)
5.10 else:
5.11 list_append(self, str(s))
6.1 --- a/lib/__builtins__/str.py Tue Jun 29 22:41:05 2021 +0200
6.2 +++ b/lib/__builtins__/str.py Tue Jun 29 23:50:13 2021 +0200
6.3 @@ -3,7 +3,7 @@
6.4 """
6.5 String objects.
6.6
6.7 -Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
6.8 +Copyright (C) 2015, 2016, 2017, 2021 Paul Boddie <paul@boddie.org.uk>
6.9
6.10 This program is free software; you can redistribute it and/or modify it under
6.11 the terms of the GNU General Public License as published by the Free Software
6.12 @@ -576,7 +576,7 @@
6.13
6.14 def upper(self): pass
6.15
6.16 -class string(basestring):
6.17 +class str(basestring):
6.18
6.19 "A plain string of bytes."
6.20
6.21 @@ -607,7 +607,7 @@
6.22 l = get_using(basestring.__get_multiple_items__, self)(start, end, step)
6.23 return "".join(l)
6.24
6.25 -def str(obj):
6.26 +def new_str(obj):
6.27
6.28 "Return the string representation of 'obj'."
6.29
7.1 --- a/templates/native/common.c Tue Jun 29 22:41:05 2021 +0200
7.2 +++ b/templates/native/common.c Tue Jun 29 23:50:13 2021 +0200
7.3 @@ -1,6 +1,6 @@
7.4 /* Common operations for native functions.
7.5
7.6 -Copyright (C) 2016, 2017, 2018 Paul Boddie <paul@boddie.org.uk>
7.7 +Copyright (C) 2016, 2017, 2018, 2021 Paul Boddie <paul@boddie.org.uk>
7.8
7.9 This program is free software; you can redistribute it and/or modify it under
7.10 the terms of the GNU General Public License as published by the Free Software
7.11 @@ -29,7 +29,7 @@
7.12 __attr __new_str(char *s, int size)
7.13 {
7.14 /* Create a new string and mutate the __data__, __size__ and __key__ attributes. */
7.15 - __attr attr = __NEWINSTANCE(__builtins___str_string);
7.16 + __attr attr = __NEWINSTANCE(__builtins___str_str);
7.17 __store_via_object(__VALUE(attr), __data__, (__attr) {.strvalue=s});
7.18 __store_via_object(__VALUE(attr), __size__, __INTVALUE(size));
7.19 __store_via_object(__VALUE(attr), __key__, __NULL);
8.1 --- a/tests/identity.py Tue Jun 29 22:41:05 2021 +0200
8.2 +++ b/tests/identity.py Tue Jun 29 23:50:13 2021 +0200
8.3 @@ -1,7 +1,7 @@
8.4 -print isinstance("string", string) # True
8.5 +print isinstance("string", str) # True
8.6 print isinstance("string", int) # False
8.7 print isinstance(123, int) # True
8.8 -print isinstance(123, string) # False
8.9 +print isinstance(123, str) # False
8.10 print
8.11
8.12 class A:
9.1 --- a/tests/unicode.py Tue Jun 29 22:41:05 2021 +0200
9.2 +++ b/tests/unicode.py Tue Jun 29 23:50:13 2021 +0200
9.3 @@ -18,31 +18,31 @@
9.4 s2 = b"\xe6\xf8\xe5"
9.5 print "ISO-8859-15 values:"
9.6 print s2 # æøå
9.7 -print s2.__class__ # __builtins__.str.string
9.8 +print s2.__class__ # __builtins__.str.str
9.9 print len(s2) # 3
9.10
9.11 s3 = "\xe6\xf8\xe5"
9.12 print "ISO-8859-15 values:"
9.13 print s3 # æøå
9.14 -print s3.__class__ # __builtins__.str.string
9.15 +print s3.__class__ # __builtins__.str.str
9.16 print len(s3) # 3
9.17
9.18 s4 = b"\u00e6\u00f8\u00e5"
9.19 print "Untranslated values:"
9.20 print s4 # \u00e6\u00f8\u00e5
9.21 -print s4.__class__ # __builtins__.str.string
9.22 +print s4.__class__ # __builtins__.str.str
9.23 print len(s4) # 18
9.24
9.25 s5 = b"\346\370\345"
9.26 print "ISO-8859-15 values:"
9.27 print s5 # æøå
9.28 -print s5.__class__ # __builtins__.str.string
9.29 +print s5.__class__ # __builtins__.str.str
9.30 print len(s5) # 3
9.31
9.32 s6 = "\346\370\345"
9.33 print "ISO-8859-15 values:"
9.34 print s6 # æøå
9.35 -print s6.__class__ # __builtins__.str.string
9.36 +print s6.__class__ # __builtins__.str.str
9.37 print len(s6) # 3
9.38
9.39 s7 = r"\346\370\345"
9.40 @@ -98,7 +98,7 @@
9.41 u5 = "\u00e6\u00f8\u00e5"
9.42 print "Unicode values:"
9.43 print u5 # æøå
9.44 -print u5.__class__ # __builtins__.unicode.ut8string
9.45 +print u5.__class__ # __builtins__.unicode.unicode
9.46 print len(u5) # 3
9.47
9.48 # Test some untranslated values.
9.49 @@ -106,7 +106,7 @@
9.50 u6 = "\\u00e6\\u00f8\\u00e5"
9.51 print "Untranslated values:"
9.52 print u6 # \u00e6\u00f8\u00e5
9.53 -print u6.__class__ # __builtins__.unicode.ut8string
9.54 +print u6.__class__ # __builtins__.unicode.unicode
9.55 print len(u6) # 18
9.56
9.57 # Test Unicode values.
9.58 @@ -114,7 +114,7 @@
9.59 u7 = u"\346\370\345"
9.60 print "Unicode values:"
9.61 print u7 # æøå
9.62 -print u7.__class__ # __builtins__.unicode.ut8string
9.63 +print u7.__class__ # __builtins__.unicode.unicode
9.64 print len(u7) # 3
9.65
9.66 # Test Unicode values.
9.67 @@ -122,7 +122,7 @@
9.68 u8 = ur"\346\370\345"
9.69 print "Untranslated values:"
9.70 print u8 # \346\370\345
9.71 -print u8.__class__ # __builtins__.unicode.ut8string
9.72 +print u8.__class__ # __builtins__.unicode.unicode
9.73 print len(u8) # 12
9.74
9.75 # Test invalid sequences.
9.76 @@ -137,7 +137,7 @@
9.77 u10 = "\u00e6\xf8\u00e5"
9.78 print "ISO-8859-15 values:"
9.79 print u10 # \u00e6ø\u00e5
9.80 -print u10.__class__ # __builtins__.str.string
9.81 +print u10.__class__ # __builtins__.str.str
9.82 print len(u10) # 13
9.83
9.84 # Combine bytes and text.
9.85 @@ -146,7 +146,7 @@
9.86 su = s + u
9.87 print "ISO-8859-15 values:"
9.88 print su # ÆØÅæøå
9.89 -print su.__class__ # __builtins__.str.string
9.90 +print su.__class__ # __builtins__.str.str
9.91 print len(su) # 6
9.92
9.93 # Combine text and bytes.
9.94 @@ -155,7 +155,7 @@
9.95 us = u + s
9.96 print "ISO-8859-15 values:"
9.97 print us # æøåÆØÅ
9.98 -print us.__class__ # __builtins__.str.string
9.99 +print us.__class__ # __builtins__.str.str
9.100 print len(us) # 6
9.101
9.102 # Combine text and text.