Commit 25230243 authored by Christian Zagrodnick's avatar Christian Zagrodnick

- Fixed bug: When an object did not implement ``__unicode__``, calling

  ``unicode(wrapped)`` was calling ``__str__`` with an unwrapped ``self``.

(reported by David Glick on zope-dev)
parent 7b4f0384
......@@ -4,6 +4,9 @@ Changelog
2.13.7 (unreleased)
-------------------
- Fixed bug: When an object did not implement ``__unicode__``, calling
``unicode(wrapped)`` was calling ``__str__`` with an unwrapped ``self``.
2.13.6 (2011-02-19)
-------------------
......
......@@ -853,7 +853,7 @@ Wrapper_unicode(Wrapper *self)
else
{
PyErr_Clear();
return PyObject_Unicode(self->obj);
return Wrapper_str(self);
}
}
......
......@@ -2501,6 +2501,22 @@ class TestUnicode(unittest.TestCase):
self.assertEqual(u'str was called', unicode(wrapped))
self.assertEqual('str was called', str(wrapped))
def test_str_fallback_should_be_called_with_wrapped_self(self):
class A(Acquisition.Implicit):
def __str__(self):
return str(self.aq_parent == outer)
outer = A()
inner = A().__of__(outer)
self.assertEqual(u'True', unicode(inner))
def test_unicode_should_be_called_with_wrapped_self(self):
class A(Acquisition.Implicit):
def __unicode__(self):
return str(self.aq_parent == outer)
outer = A()
inner = A().__of__(outer)
self.assertEqual(u'True', unicode(inner))
def test_suite():
return unittest.TestSuite((
......
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