zope.proxy does not proxy __unicode__

Bug #1262702 reported by Marius Gedminas
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
zope.proxy
Won't Fix
Undecided
Unassigned

Bug Description

See the failing tests I committed in a branch:
https://github.com/zopefoundation/zope.proxy/commit/03efa840af3e0a4fdddf4e622da235258b5588da

I'm not sure how to fix this. It appears that CPython's PyTypeObject doesn't have a tp_unicode slot. Can anyone with more C API experience chime in? How would you define a C class with a custom __unicode__ representation?

Revision history for this message
Marius Gedminas (mgedmin) wrote :

FWIW here's what the test failures look like:

mg@platonas: ~/src/new-zope-order/zope.proxy [git:master *$=] $ bin/test -pvc
Running tests at level 1
Running zope.testrunner.layer.UnitTests tests:
  Set up zope.testrunner.layer.UnitTests in 0.000 seconds.
  Running:
    83/151 (55.0%) test___unicode__of_custom_class (zope.proxy.tests.test_proxy.ProxyBaseTestCase)

Failure in test test___unicode__of_custom_class (zope.proxy.tests.test_proxy.ProxyBaseTestCase)
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/case.py", line 331, in run
    testMethod()
  File "/home/mg/src/new-zope-order/zope.proxy/src/zope/proxy/tests/test_proxy.py", line 127, in test___unicode__of_custom_class
    self.assertEqual(unicode(proxy), u'Hello, \u2603')
  File "/usr/lib/python2.7/unittest/case.py", line 515, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python2.7/unittest/case.py", line 926, in assertMultiLineEqual
    self.fail(self._formatMessage(msg, standardMsg))
  File "/usr/lib/python2.7/unittest/case.py", line 412, in fail
    raise self.failureException(msg)
AssertionError: u'<zope.proxy.tests.test_proxy.CustomClass object at 0x2d42e10>' != u'Hello, \u2603'
- <zope.proxy.tests.test_proxy.CustomClass object at 0x2d42e10>
+ Hello, \u2603

    84/151 (55.6%) test___unicode__of_unicode (zope.proxy.tests.test_proxy.ProxyBaseTestCase)

Error in test test___unicode__of_unicode (zope.proxy.tests.test_proxy.ProxyBaseTestCase)
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/case.py", line 331, in run
    testMethod()
  File "/home/mg/src/new-zope-order/zope.proxy/src/zope/proxy/tests/test_proxy.py", line 117, in test___unicode__of_unicode
    self.assertEqual(unicode(proxy), s)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2603' in position 7: ordinal not in range(128)

  Ran 151 tests with 1 failures, 1 errors, 0 skipped in 0.032 seconds.
Tearing down left over layers:
  Tear down zope.testrunner.layer.UnitTests in 0.000 seconds.

Tests with errors:
   test___unicode__of_unicode (zope.proxy.tests.test_proxy.ProxyBaseTestCase)

Tests with failures:
   test___unicode__of_custom_class (zope.proxy.tests.test_proxy.ProxyBaseTestCase)

[exited with 1]

Revision history for this message
Tres Seaver (tseaver) wrote :

There is no slot: you just define a '__unicode__' method for the
extension type. E.g.::

    static PyMethodDef MyType_methods[] = {
        {"__unicode__", (PyCFunction)BaseException_unicode, METH_NOARGS },
        {NULL, NULL, 0, NULL},
    };

binding those methods in the type declaration struct::

    static PyTypeObject _MyType = {
        PyObject_HEAD_INIT(NULL)
        0, /*ob_size*/
        EXC_MODULE_NAME "MyType", /*tp_name*/
        ...
        MyType_methods, /* tp_methods */
        ...
    };

Revision history for this message
Tres Seaver (tseaver) wrote :
Changed in zope.proxy:
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.