summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-10-12 02:38:24 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-10-12 02:38:24 (GMT)
commitfc57ccb98248b4a8f4ba4debdf3791970b136c4d (patch)
treea0aba8c9a056e54a0faa26a619d653905d773540 /Lib
parent401a76dcab6766d85bfcbb7e3705ee376e97bc06 (diff)
downloadcpython-fc57ccb98248b4a8f4ba4debdf3791970b136c4d.zip
cpython-fc57ccb98248b4a8f4ba4debdf3791970b136c4d.tar.gz
cpython-fc57ccb98248b4a8f4ba4debdf3791970b136c4d.tar.bz2
SF bug [#470040] ParseTuple t# vs subclasses.
inherit_slots(): tp_as_buffer was getting inherited as if it were a method pointer, rather than a pointer to a vector of method pointers. As a result, inheriting from a type that implemented buffer methods was ineffective, leaving all the tp_as_buffer slots NULL in the subclass.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_descr.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 1768a6d..e5ee591 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -2298,7 +2298,37 @@ def subclasspropagation():
pass
else:
raise TestFailed, "d.foo should be undefined now"
-
+
+def buffer_inherit():
+ import binascii
+ # SF bug [#470040] ParseTuple t# vs subclasses.
+ if verbose:
+ print "Testing that buffer interface is inherited ..."
+
+ class MyStr(str):
+ pass
+ base = 'abc'
+ m = MyStr(base)
+ # b2a_hex uses the buffer interface to get its argument's value, via
+ # PyArg_ParseTuple 't#' code.
+ vereq(binascii.b2a_hex(m), binascii.b2a_hex(base))
+
+ # It's not clear that unicode will continue to support the character
+ # buffer interface, and this test will fail if that's taken away.
+ class MyUni(unicode):
+ pass
+ base = u'abc'
+ m = MyUni(base)
+ vereq(binascii.b2a_hex(m), binascii.b2a_hex(base))
+
+ class MyInt(int):
+ pass
+ m = MyInt(42)
+ try:
+ binascii.b2a_hex(m)
+ raise TestFailed('subclass of int should not have a buffer interface')
+ except TypeError:
+ pass
def test_main():
class_docstrings()
@@ -2347,6 +2377,7 @@ def test_main():
copies()
binopoverride()
subclasspropagation()
+ buffer_inherit()
if verbose: print "All OK"
if __name__ == "__main__":