[Python-checkins] r79282 - in python/branches/release31-maint: Lib/test/test_unicode.py Misc/NEWS Objects/unicodeobject.c

victor.stinner python-checkins at python.org
Mon Mar 22 13:53:14 CET 2010


Author: victor.stinner
Date: Mon Mar 22 13:53:14 2010
New Revision: 79282

Log:
Merged revisions 79281 via svnmerge from 
svn+ssh://pythondev@svn.python.org/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://pythondev@svn.python.org/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.
  ........
................


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Lib/test/test_unicode.py
   python/branches/release31-maint/Misc/NEWS
   python/branches/release31-maint/Objects/unicodeobject.c

Modified: python/branches/release31-maint/Lib/test/test_unicode.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_unicode.py	(original)
+++ python/branches/release31-maint/Lib/test/test_unicode.py	Mon Mar 22 13:53:14 2010
@@ -1223,6 +1223,14 @@
         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__)

Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS	(original)
+++ python/branches/release31-maint/Misc/NEWS	Mon Mar 22 13:53:14 2010
@@ -9,6 +9,11 @@
 
 *Release date: 20XX-XX-XX*
 
+Core and Builtins
+-----------------
+
+- Issue #1583863: An str subclass can now override the __str__ method
+
 Library
 -------
 

Modified: python/branches/release31-maint/Objects/unicodeobject.c
==============================================================================
--- python/branches/release31-maint/Objects/unicodeobject.c	(original)
+++ python/branches/release31-maint/Objects/unicodeobject.c	Mon Mar 22 13:53:14 2010
@@ -9308,7 +9308,7 @@
             case 's':
             case 'r':
             case 'a':
-                if (PyUnicode_Check(v) && c == 's') {
+                if (PyUnicode_CheckExact(v) && c == 's') {
                     temp = v;
                     Py_INCREF(temp);
                 }


More information about the Python-checkins mailing list