diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-03-22 12:24:37 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-03-22 12:24:37 (GMT) |
commit | 95affc44495806a540f4d997d13361cc388b1a7e (patch) | |
tree | eb554a0bbbf05e8570190b42d877c1ae31c68a81 | |
parent | eef159bd176ffeaae7cdc8450e3d6168fbfe4a59 (diff) | |
download | cpython-95affc44495806a540f4d997d13361cc388b1a7e.zip cpython-95affc44495806a540f4d997d13361cc388b1a7e.tar.gz cpython-95affc44495806a540f4d997d13361cc388b1a7e.tar.bz2 |
Issue #1583863: An unicode subclass can now override the __str__ method
-rw-r--r-- | Lib/test/test_unicode.py | 11 | ||||
-rw-r--r-- | Misc/NEWS | 2 | ||||
-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 a859c0f..973a008 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -1193,6 +1193,17 @@ class UnicodeTest( self.assertRaises(MemoryError, alloc) self.assertRaises(MemoryError, alloc) + def test_format_subclass(self): + class U(unicode): + def __str__(self): + return '__str__ overridden' + def __unicode__(self): + return u'__unicode__ overridden' + u = U(u'xxx') + self.assertEquals("%s" % u, u'__unicode__ overridden') + self.assertEquals("{}".format(u), u'__unicode__ overridden') + + def test_main(): test_support.run_unittest(__name__) @@ -12,6 +12,8 @@ What's New in Python 2.7 beta 1? Core and Builtins ----------------- +- Issue #1583863: An unicode subclass can now override the __str__ method + - Issue #6474: Make error message from passing an inadequate number of keyword arguments to a function correct. diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 113a460..82af3a2 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8466,7 +8466,7 @@ PyObject *PyUnicode_Format(PyObject *format, case 's': case 'r': - if (PyUnicode_Check(v) && c == 's') { + if (PyUnicode_CheckExact(v) && c == 's') { temp = v; Py_INCREF(temp); } |