Commit 95affc44 authored by Victor Stinner's avatar Victor Stinner

Issue #1583863: An unicode subclass can now override the __str__ method

parent eef159bd
...@@ -1193,6 +1193,17 @@ class UnicodeTest( ...@@ -1193,6 +1193,17 @@ class UnicodeTest(
self.assertRaises(MemoryError, alloc) self.assertRaises(MemoryError, alloc)
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(): def test_main():
test_support.run_unittest(__name__) test_support.run_unittest(__name__)
......
...@@ -12,6 +12,8 @@ What's New in Python 2.7 beta 1? ...@@ -12,6 +12,8 @@ What's New in Python 2.7 beta 1?
Core and Builtins 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 - Issue #6474: Make error message from passing an inadequate number of keyword
arguments to a function correct. arguments to a function correct.
......
...@@ -8466,7 +8466,7 @@ PyObject *PyUnicode_Format(PyObject *format, ...@@ -8466,7 +8466,7 @@ PyObject *PyUnicode_Format(PyObject *format,
case 's': case 's':
case 'r': case 'r':
if (PyUnicode_Check(v) && c == 's') { if (PyUnicode_CheckExact(v) && c == 's') {
temp = v; temp = v;
Py_INCREF(temp); Py_INCREF(temp);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment