[pypy-svn] r60952 - in pypy/trunk/pypy: module/__builtin__ objspace/std/test

fijal at codespeak.net fijal at codespeak.net
Wed Jan 14 14:08:30 CET 2009


Author: fijal
Date: Wed Jan 14 14:08:28 2009
New Revision: 60952

Modified:
   pypy/trunk/pypy/module/__builtin__/interp_classobj.py
   pypy/trunk/pypy/objspace/std/test/test_unicodeobject.py
Log:
a test and a fix for oldstyle classes __unicode__


Modified: pypy/trunk/pypy/module/__builtin__/interp_classobj.py
==============================================================================
--- pypy/trunk/pypy/module/__builtin__/interp_classobj.py	(original)
+++ pypy/trunk/pypy/module/__builtin__/interp_classobj.py	Wed Jan 14 14:08:28 2009
@@ -416,6 +416,12 @@
             return self.descr_repr(space)
         return space.call_function(w_meth)
 
+    def descr_unicode(self, space):
+        w_meth = self.getattr(space, space.wrap('__unicode__'), False)
+        if w_meth is None:
+            return self.descr_repr(space)
+        return space.call_function(w_meth)
+
     def descr_len(self, space):
         w_meth = self.getattr(space, space.wrap('__len__'))
         w_result = space.call_function(w_meth)
@@ -696,6 +702,8 @@
                           unwrap_spec=['self', ObjSpace]),
     __str__ = interp2app(W_InstanceObject.descr_str,
                          unwrap_spec=['self', ObjSpace]),
+    __unicode__ = interp2app(W_InstanceObject.descr_unicode,
+                         unwrap_spec=['self', ObjSpace]),
     __len__ = interp2app(W_InstanceObject.descr_len,
                          unwrap_spec=['self', ObjSpace]),
     __getitem__ = interp2app(W_InstanceObject.descr_getitem,

Modified: pypy/trunk/pypy/objspace/std/test/test_unicodeobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_unicodeobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/test/test_unicodeobject.py	Wed Jan 14 14:08:28 2009
@@ -686,7 +686,6 @@
         assert s == u'\u1234'
 
     def test_formatting_unicode__str__2(self):
-        skip('XXX: do we really want to have such behaviour? CPython has not tests for that')
         class A:
             def __str__(self):
                 return u'baz'
@@ -708,3 +707,22 @@
             def __unicode__(self):
                 return u"world"
         assert unicode(Foo9("hello")) == u"world"
+
+    def test_class_with_both_str_and_unicode(self):
+        class A(object):
+            def __str__(self):
+                return 'foo'
+
+            def __unicode__(self):
+                return u'bar'
+
+        assert unicode(A()) == u'bar'
+
+        class A:
+            def __str__(self):
+                return 'foo'
+
+            def __unicode__(self):
+                return u'bar'
+
+        assert unicode(A()) == u'bar'



More information about the Pypy-commit mailing list