[Python-checkins] cpython: Issue #26243: Only the level argument to zlib.compress() is keyword argument

serhiy.storchaka python-checkins at python.org
Sat Jun 25 15:43:23 EDT 2016


https://hg.python.org/cpython/rev/01f82a7a1250
changeset:   102170:01f82a7a1250
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sat Jun 25 22:43:05 2016 +0300
summary:
  Issue #26243: Only the level argument to zlib.compress() is keyword argument
now.  The first argument is positional-only.

files:
  Doc/library/zlib.rst          |  2 +-
  Lib/test/test_zlib.py         |  4 +++-
  Misc/NEWS                     |  3 +++
  Modules/clinic/zlibmodule.c.h |  6 +++---
  Modules/zlibmodule.c          |  3 ++-
  5 files changed, 12 insertions(+), 6 deletions(-)


diff --git a/Doc/library/zlib.rst b/Doc/library/zlib.rst
--- a/Doc/library/zlib.rst
+++ b/Doc/library/zlib.rst
@@ -58,7 +58,7 @@
    Raises the :exc:`error` exception if any error occurs.
 
    .. versionchanged:: 3.6
-      Keyword arguments are now supported.
+      *level* is now supported as keyword arguments.
 
 
 .. function:: compressobj(level=-1, method=DEFLATED, wbits=15, memLevel=8, strategy=Z_DEFAULT_STRATEGY[, zdict])
diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py
--- a/Lib/test/test_zlib.py
+++ b/Lib/test/test_zlib.py
@@ -163,8 +163,10 @@
         self.assertEqual(zlib.decompress(x), HAMLET_SCENE)
 
     def test_keywords(self):
-        x = zlib.compress(data=HAMLET_SCENE, level=3)
+        x = zlib.compress(HAMLET_SCENE, level=3)
         self.assertEqual(zlib.decompress(x), HAMLET_SCENE)
+        with self.assertRaises(TypeError):
+            zlib.compress(data=HAMLET_SCENE, level=3)
 
     def test_speech128(self):
         # compress more data
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Library
 -------
 
+- Issue #26243: Only the level argument to zlib.compress() is keyword argument
+  now.  The first argument is positional-only.
+
 - Issue #27038: Expose the DirEntry type as os.DirEntry. Code patch by
   Jelle Zijlstra.
 
diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h
--- a/Modules/clinic/zlibmodule.c.h
+++ b/Modules/clinic/zlibmodule.c.h
@@ -3,7 +3,7 @@
 [clinic start generated code]*/
 
 PyDoc_STRVAR(zlib_compress__doc__,
-"compress($module, /, data, level=Z_DEFAULT_COMPRESSION)\n"
+"compress($module, data, /, level=Z_DEFAULT_COMPRESSION)\n"
 "--\n"
 "\n"
 "Returns a bytes object containing compressed data.\n"
@@ -23,7 +23,7 @@
 zlib_compress(PyModuleDef *module, PyObject *args, PyObject *kwargs)
 {
     PyObject *return_value = NULL;
-    static char *_keywords[] = {"data", "level", NULL};
+    static char *_keywords[] = {"", "level", NULL};
     Py_buffer data = {NULL, NULL};
     int level = Z_DEFAULT_COMPRESSION;
 
@@ -460,4 +460,4 @@
 #ifndef ZLIB_COMPRESS_COPY_METHODDEF
     #define ZLIB_COMPRESS_COPY_METHODDEF
 #endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */
-/*[clinic end generated code: output=9bd8a093baa653b2 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ba904dec30cc1a1a input=a9049054013a1b77]*/
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -143,6 +143,7 @@
 
     data: Py_buffer
         Binary data to be compressed.
+    /
     level: int(c_default="Z_DEFAULT_COMPRESSION") = Z_DEFAULT_COMPRESSION
         Compression level, in 0-9 or -1.
 
@@ -151,7 +152,7 @@
 
 static PyObject *
 zlib_compress_impl(PyModuleDef *module, Py_buffer *data, int level)
-/*[clinic end generated code: output=1b97589132b203b4 input=abed30f4fa14e213]*/
+/*[clinic end generated code: output=1b97589132b203b4 input=638d54b6315dbed3]*/
 {
     PyObject *ReturnVal = NULL;
     Byte *input, *output = NULL;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list