More bug 460020: lots of string optimizations inhibited for string

subclasses, all "the usual" ones (slicing etc), plus replace, translate,
ljust, rjust, center and strip.  I don't know how to be sure they've all
been caught.

Question:  Should we complain if someone tries to intern an instance of
a string subclass?  I hate to slow any code on those paths.
This commit is contained in:
Tim Peters 2001-09-12 02:18:30 +00:00
parent ee0fe0b743
commit 8fa5dd0601
2 changed files with 71 additions and 81 deletions

View file

@ -1481,9 +1481,32 @@ def inherits():
verify(str(s) == "12345")
verify(str(s).__class__ is str)
s = madstring("\x00" * 5)
verify(str(s) == "\x00" * 5)
base = "\x00" * 5
s = madstring(base)
verify(str(s) == base)
verify(str(s).__class__ is str)
verify((s + "").__class__ is str)
verify(("" + s).__class__ is str)
verify((s * 0).__class__ is str)
verify((s * 1).__class__ is str)
verify((s * 2).__class__ is str)
verify(s[:].__class__ is str)
verify(s[0:0].__class__ is str)
verify(s.strip().__class__ is str)
identitytab = ''.join([chr(i) for i in range(256)])
verify(s.translate(identitytab).__class__ is str)
verify(s.translate(identitytab) == base)
verify(s.translate(identitytab, "x").__class__ is str)
verify(s.translate(identitytab, "x") == base)
verify(s.translate(identitytab, "\x00") == "")
verify(s.replace("x", "x").__class__ is str)
verify(s.replace("x", "x") == base)
verify(s.ljust(len(s)).__class__ is str)
verify(s.ljust(len(s)) == base)
verify(s.rjust(len(s)).__class__ is str)
verify(s.rjust(len(s)) == base)
verify(s.center(len(s)).__class__ is str)
verify(s.center(len(s)) == base)
class madunicode(unicode):
_rev = None