Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 95657cd

Browse files
Issue #26243: Only the level argument to zlib.compress() is keyword argument
now. The first argument is positional-only.
1 parent 696c35e commit 95657cd

5 files changed

Lines changed: 12 additions & 6 deletions

File tree

Doc/library/zlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The available exception and functions in this module are:
5858
Raises the :exc:`error` exception if any error occurs.
5959

6060
.. versionchanged:: 3.6
61-
Keyword arguments are now supported.
61+
*level* is now supported as keyword arguments.
6262

6363

6464
.. function:: compressobj(level=-1, method=DEFLATED, wbits=15, memLevel=8, strategy=Z_DEFAULT_STRATEGY[, zdict])

Lib/test/test_zlib.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ def test_speech(self):
163163
self.assertEqual(zlib.decompress(x), HAMLET_SCENE)
164164

165165
def test_keywords(self):
166-
x = zlib.compress(data=HAMLET_SCENE, level=3)
166+
x = zlib.compress(HAMLET_SCENE, level=3)
167167
self.assertEqual(zlib.decompress(x), HAMLET_SCENE)
168+
with self.assertRaises(TypeError):
169+
zlib.compress(data=HAMLET_SCENE, level=3)
168170

169171
def test_speech128(self):
170172
# compress more data

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.6.0 alpha 3
1010
Library
1111
-------
1212

13+
- Issue #26243: Only the level argument to zlib.compress() is keyword argument
14+
now. The first argument is positional-only.
15+
1316
- Issue #27038: Expose the DirEntry type as os.DirEntry. Code patch by
1417
Jelle Zijlstra.
1518

Modules/clinic/zlibmodule.c.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ preserve
33
[clinic start generated code]*/
44

55
PyDoc_STRVAR(zlib_compress__doc__,
6-
"compress($module, /, data, level=Z_DEFAULT_COMPRESSION)\n"
6+
"compress($module, data, /, level=Z_DEFAULT_COMPRESSION)\n"
77
"--\n"
88
"\n"
99
"Returns a bytes object containing compressed data.\n"
@@ -23,7 +23,7 @@ static PyObject *
2323
zlib_compress(PyModuleDef *module, PyObject *args, PyObject *kwargs)
2424
{
2525
PyObject *return_value = NULL;
26-
static char *_keywords[] = {"data", "level", NULL};
26+
static char *_keywords[] = {"", "level", NULL};
2727
Py_buffer data = {NULL, NULL};
2828
int level = Z_DEFAULT_COMPRESSION;
2929

@@ -460,4 +460,4 @@ zlib_crc32(PyModuleDef *module, PyObject *args)
460460
#ifndef ZLIB_COMPRESS_COPY_METHODDEF
461461
#define ZLIB_COMPRESS_COPY_METHODDEF
462462
#endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */
463-
/*[clinic end generated code: output=9bd8a093baa653b2 input=a9049054013a1b77]*/
463+
/*[clinic end generated code: output=ba904dec30cc1a1a input=a9049054013a1b77]*/

Modules/zlibmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ zlib.compress
143143
144144
data: Py_buffer
145145
Binary data to be compressed.
146+
/
146147
level: int(c_default="Z_DEFAULT_COMPRESSION") = Z_DEFAULT_COMPRESSION
147148
Compression level, in 0-9 or -1.
148149
@@ -151,7 +152,7 @@ Returns a bytes object containing compressed data.
151152

152153
static PyObject *
153154
zlib_compress_impl(PyModuleDef *module, Py_buffer *data, int level)
154-
/*[clinic end generated code: output=1b97589132b203b4 input=abed30f4fa14e213]*/
155+
/*[clinic end generated code: output=1b97589132b203b4 input=638d54b6315dbed3]*/
155156
{
156157
PyObject *ReturnVal = NULL;
157158
Byte *input, *output = NULL;

0 commit comments

Comments
 (0)