[Python-checkins] python/dist/src/Lib/test test_builtin.py, 1.33,
1.34
jhylton at users.sourceforge.net
jhylton at users.sourceforge.net
Sat Aug 7 21:20:07 CEST 2004
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9225/Lib/test
Modified Files:
test_builtin.py
Log Message:
Subclasses of string can no longer be interned. The semantics of
interning were not clear here -- a subclass could be mutable, for
example -- and had bugs. Explicitly interning a subclass of string
via intern() will raise a TypeError. Internal operations that attempt
to intern a string subclass will have no effect.
Added a few tests to test_builtin that includes the old buggy code and
verifies that calls like PyObject_SetAttr() don't fail. Perhaps these
tests should have gone in test_string.
Index: test_builtin.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_builtin.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** test_builtin.py 7 Aug 2004 04:55:30 -0000 1.33
--- test_builtin.py 7 Aug 2004 19:20:05 -0000 1.34
***************
*** 609,612 ****
--- 609,629 ----
self.assert_(intern(s2) is s)
+ # Subclasses of string can't be interned, because they
+ # provide too much opportunity for insane things to happen.
+ # We don't want them in the interned dict and if they aren't
+ # actually interned, we don't want to create the appearance
+ # that they are by allowing intern() to succeeed.
+ class S(str):
+ def __hash__(self):
+ return 123
+
+ self.assertRaises(TypeError, intern, S("abc"))
+
+ # It's still safe to pass these strings to routines that
+ # call intern internally, e.g. PyObject_SetAttr().
+ s = S("abc")
+ setattr(s, s, s)
+ self.assertEqual(getattr(s, s), s)
+
def test_iter(self):
self.assertRaises(TypeError, iter)
More information about the Python-checkins
mailing list