diff options
-rw-r--r-- | Lib/test/test_unicode.py | 8 | ||||
-rw-r--r-- | Misc/NEWS | 5 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 2 |
3 files changed, 14 insertions, 1 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 7f87b43..6e4f048 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -1223,6 +1223,14 @@ class UnicodeTest( self.assertRaises(MemoryError, alloc) self.assertRaises(MemoryError, alloc) + def test_format_subclass(self): + class S(str): + def __str__(self): + return '__str__ overridden' + s = S('xxx') + self.assertEquals("%s" % s, '__str__ overridden') + self.assertEquals("{}".format(s), '__str__ overridden') + def test_main(): support.run_unittest(__name__) @@ -9,6 +9,11 @@ What's New in Python 3.1.3? *Release date: 20XX-XX-XX* +Core and Builtins +----------------- + +- Issue #1583863: An str subclass can now override the __str__ method + Library ------- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 5fd2372..2ccec90 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -9308,7 +9308,7 @@ PyObject *PyUnicode_Format(PyObject *format, case 's': case 'r': case 'a': - if (PyUnicode_Check(v) && c == 's') { + if (PyUnicode_CheckExact(v) && c == 's') { temp = v; Py_INCREF(temp); } |