Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit abdb21a

Browse files
author
Victor Stinner
committed
Merged revisions 79281 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ................ r79281 | victor.stinner | 2010-03-22 13:50:40 +0100 (lun., 22 mars 2010) | 16 lines Merged revisions 79278,79280 via svnmerge from svn+ssh://[email protected]/python/trunk ........ r79278 | victor.stinner | 2010-03-22 13:24:37 +0100 (lun., 22 mars 2010) | 2 lines Issue #1583863: An unicode subclass can now override the __str__ method ........ r79280 | victor.stinner | 2010-03-22 13:36:28 +0100 (lun., 22 mars 2010) | 5 lines Fix the NEWS about my last commit: an unicode subclass can now override the __unicode__ method (and not the __str__ method). Simplify also the testcase. ........ ................
1 parent 6a11edb commit abdb21a

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

Lib/test/test_unicode.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,14 @@ def test_raiseMemError(self):
12231223
self.assertRaises(MemoryError, alloc)
12241224
self.assertRaises(MemoryError, alloc)
12251225

1226+
def test_format_subclass(self):
1227+
class S(str):
1228+
def __str__(self):
1229+
return '__str__ overridden'
1230+
s = S('xxx')
1231+
self.assertEquals("%s" % s, '__str__ overridden')
1232+
self.assertEquals("{}".format(s), '__str__ overridden')
1233+
12261234

12271235
def test_main():
12281236
support.run_unittest(__name__)

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ What's New in Python 3.1.3?
99

1010
*Release date: 20XX-XX-XX*
1111

12+
Core and Builtins
13+
-----------------
14+
15+
- Issue #1583863: An str subclass can now override the __str__ method
16+
1217
Library
1318
-------
1419

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9308,7 +9308,7 @@ PyObject *PyUnicode_Format(PyObject *format,
93089308
case 's':
93099309
case 'r':
93109310
case 'a':
9311-
if (PyUnicode_Check(v) && c == 's') {
9311+
if (PyUnicode_CheckExact(v) && c == 's') {
93129312
temp = v;
93139313
Py_INCREF(temp);
93149314
}

0 commit comments

Comments
 (0)