summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_struct.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-02-02 11:09:30 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2017-02-02 11:09:30 (GMT)
commit3f2d10132d9835b1ebda3283643fbbfdb0851b91 (patch)
treec510112913f972aac1520a60a487445895fe158f /Lib/test/test_struct.py
parentfd6d0d2a18bb487ec06dbbeb1a53d0ac13384cfe (diff)
downloadcpython-3f2d10132d9835b1ebda3283643fbbfdb0851b91.zip
cpython-3f2d10132d9835b1ebda3283643fbbfdb0851b91.tar.gz
cpython-3f2d10132d9835b1ebda3283643fbbfdb0851b91.tar.bz2
Issue #29300: Convert _struct module to Argument Clinic
* The struct module now requires contiguous buffers. * Convert most functions and methods of the _struct module to Argument Clinic * Use "Py_buffer" type for the "buffer" argument. Argument Clinic is responsible to create and release the Py_buffer object. * Use "PyStructObject *" type for self to avoid explicit conversions. * Add an unit test on the _struct.Struct.unpack_from() method to test passing arguments as keywords. * Rephrase docstrings. * Rename "fmt" argument to "format" in docstrings and the documentation. As a side effect, functions and methods which used METH_VARARGS calling convention like struct.pack() now use the METH_FASTCALL calling convention which avoids the creation of temporary tuple to pass positional arguments and so is faster. For example, struct.pack("i", 1) becomes 1.56x faster (-36%):: $ ./python -m perf timeit \ -s 'import struct; pack=struct.pack' 'pack("i", 1)' \ --compare-to=../default-ref/python Median +- std dev: 119 ns +- 1 ns -> 76.8 ns +- 0.4 ns: 1.56x faster (-36%) Significant (t=295.91) Patch co-written with Serhiy Storchaka.
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r--Lib/test/test_struct.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 4d9d601..be00475 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -412,6 +412,10 @@ class StructTest(unittest.TestCase):
for i in range(6, len(test_string) + 1):
self.assertRaises(struct.error, struct.unpack_from, fmt, data, i)
+ # keyword arguments
+ self.assertEqual(s.unpack_from(buffer=test_string, offset=2),
+ (b'cd01',))
+
def test_pack_into(self):
test_string = b'Reykjavik rocks, eow!'
writable_buf = array.array('b', b' '*100)