diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-11-19 03:10:36 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-11-19 03:10:36 (GMT) |
commit | a1f9c0423992f731778e3389eba2c87f864a6ba1 (patch) | |
tree | 8100e2a249f3c1852032a98a721c5d01ee788a1e | |
parent | d3a77c0ad3d933f9ce6f3e8e6c983bfb47e89b8e (diff) | |
download | cpython-a1f9c0423992f731778e3389eba2c87f864a6ba1.zip cpython-a1f9c0423992f731778e3389eba2c87f864a6ba1.tar.gz cpython-a1f9c0423992f731778e3389eba2c87f864a6ba1.tar.bz2 |
Merged revisions 76396 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r76396 | benjamin.peterson | 2009-11-18 21:08:32 -0600 (Wed, 18 Nov 2009) | 10 lines
fix __bytes__ handling here in py3x
Merged revisions 76395 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76395 | benjamin.peterson | 2009-11-18 21:00:02 -0600 (Wed, 18 Nov 2009) | 1 line
#5037 proxy __unicode__ correctly
........
................
-rw-r--r-- | Lib/test/test_weakref.py | 11 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Objects/weakrefobject.c | 17 |
3 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index ffa28a6..ecf1976 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -183,6 +183,17 @@ class ReferencesTestCase(TestBase): self.assertEqual(L3[:5], p3[:5]) self.assertEqual(L3[2:5], p3[2:5]) + def test_proxy_unicode(self): + # See bug 5037 + class C(object): + def __str__(self): + return "string" + def __bytes__(self): + return b"bytes" + instance = C() + self.assertTrue("__bytes__" in dir(weakref.proxy(instance))) + self.assertEqual(bytes(weakref.proxy(instance)), b"bytes") + def test_proxy_index(self): class C: def __index__(self): @@ -49,6 +49,9 @@ Library - Issue #3976: pprint for sets, frozensets, and dicts now succeed when they contain unorderable types. +- Issue #5037: Proxy the __unicode__ special method instead to __unicode__ + instead of __str__. + - Issue #7341: Close the internal file object in the TarFile constructor in case of an error. diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index 214dd95..27f015d 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -435,6 +435,13 @@ proxy_checkref(PyWeakReference *proxy) return generic(proxy, v, w); \ } +#define WRAP_METHOD(method, special) \ + static PyObject * \ + method(PyObject *proxy) { \ + UNWRAP(proxy); \ + return PyObject_CallMethod(proxy, special, ""); \ + } + /* direct slots */ @@ -576,6 +583,15 @@ proxy_iternext(PyWeakReference *proxy) } +WRAP_METHOD(proxy_bytes, "__bytes__"); + + +static PyMethodDef proxy_methods[] = { + {"__bytes__", (PyCFunction)proxy_bytes, METH_NOARGS}, + {NULL, NULL} +}; + + static PyNumberMethods proxy_as_number = { proxy_add, /*nb_add*/ proxy_sub, /*nb_subtract*/ @@ -661,6 +677,7 @@ _PyWeakref_ProxyType = { 0, /* tp_weaklistoffset */ (getiterfunc)proxy_iter, /* tp_iter */ (iternextfunc)proxy_iternext, /* tp_iternext */ + proxy_methods, /* tp_methods */ }; |