Skip to content

gh-95534: Convert ZlibDecompressor.__new__ to AC #137923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 89 additions & 8 deletions Modules/clinic/zlibmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 29 additions & 38 deletions Modules/zlibmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1369,9 +1369,9 @@ typedef struct {
} ZlibDecompressor;

/*[clinic input]
class zlib.ZlibDecompressor "ZlibDecompressor *" "&ZlibDecompressorType"
class zlib._ZlibDecompressor "ZlibDecompressor *" "&ZlibDecompressorType"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=0658178ab94645df]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=49151d1d703e6bcc]*/

static void
ZlibDecompressor_dealloc(PyObject *op)
Expand Down Expand Up @@ -1670,7 +1670,7 @@ decompress(ZlibDecompressor *self, uint8_t *data,

/*[clinic input]
@permit_long_docstring_body
zlib.ZlibDecompressor.decompress
zlib._ZlibDecompressor.decompress

data: Py_buffer
max_length: Py_ssize_t=-1
Expand All @@ -1692,9 +1692,10 @@ the unused_data attribute.
[clinic start generated code]*/

static PyObject *
zlib_ZlibDecompressor_decompress_impl(ZlibDecompressor *self,
Py_buffer *data, Py_ssize_t max_length)
/*[clinic end generated code: output=990d32787b775f85 input=fcf9f974de5d02b1]*/
zlib__ZlibDecompressor_decompress_impl(ZlibDecompressor *self,
Py_buffer *data,
Py_ssize_t max_length)
/*[clinic end generated code: output=ac00dcf73e843e99 input=c9278e791be1152b]*/

{
PyObject *result = NULL;
Expand All @@ -1710,38 +1711,28 @@ zlib_ZlibDecompressor_decompress_impl(ZlibDecompressor *self,
return result;
}

PyDoc_STRVAR(ZlibDecompressor__new____doc__,
"_ZlibDecompressor(wbits=15, zdict=b\'\')\n"
"--\n"
"\n"
"Create a decompressor object for decompressing data incrementally.\n"
"\n"
" wbits = 15\n"
" zdict\n"
" The predefined compression dictionary. This is a sequence of bytes\n"
" (such as a bytes object) containing subsequences that are expected\n"
" to occur frequently in the data that is to be compressed. Those\n"
" subsequences that are expected to be most common should come at the\n"
" end of the dictionary. This must be the same dictionary as used by the\n"
" compressor that produced the input data.\n"
"\n");
/*[clinic input]
@classmethod
zlib._ZlibDecompressor.__new__

wbits: int(c_default='MAX_WBITS') = MAX_WBITS
zdict: object(c_default='NULL') = b''
The predefined compression dictionary. This is a sequence of bytes
(such as a bytes object) containing subsequences that are expected
to occur frequently in the data that is to be compressed. Those
subsequences that are expected to be most common should come at the
end of the dictionary. This must be the same dictionary as used by the
compressor that produced the input data.

Create a decompressor object for decompressing data incrementally.
[clinic start generated code]*/

static PyObject *
ZlibDecompressor__new__(PyTypeObject *cls,
PyObject *args,
PyObject *kwargs)
zlib__ZlibDecompressor_impl(PyTypeObject *type, int wbits, PyObject *zdict)
/*[clinic end generated code: output=1065607df0d33baa input=9ebad0be6de226e2]*/
{
static char *keywords[] = {"wbits", "zdict", NULL};
static const char * const format = "|iO:_ZlibDecompressor";
int wbits = MAX_WBITS;
PyObject *zdict = NULL;
zlibstate *state = PyType_GetModuleState(cls);

if (!PyArg_ParseTupleAndKeywords(
args, kwargs, format, keywords, &wbits, &zdict)) {
return NULL;
}
ZlibDecompressor *self = PyObject_New(ZlibDecompressor, cls);
zlibstate *state = PyType_GetModuleState(type);
ZlibDecompressor *self = PyObject_New(ZlibDecompressor, type);
if (self == NULL) {
return NULL;
}
Expand Down Expand Up @@ -1817,7 +1808,7 @@ static PyMethodDef Decomp_methods[] =
};

static PyMethodDef ZlibDecompressor_methods[] = {
ZLIB_ZLIBDECOMPRESSOR_DECOMPRESS_METHODDEF
ZLIB__ZLIBDECOMPRESSOR_DECOMPRESS_METHODDEF
{NULL}
};

Expand Down Expand Up @@ -2052,8 +2043,8 @@ static PyType_Spec Decomptype_spec = {
static PyType_Slot ZlibDecompressor_type_slots[] = {
{Py_tp_dealloc, ZlibDecompressor_dealloc},
{Py_tp_members, ZlibDecompressor_members},
{Py_tp_new, ZlibDecompressor__new__},
{Py_tp_doc, (char *)ZlibDecompressor__new____doc__},
{Py_tp_new, zlib__ZlibDecompressor},
{Py_tp_doc, (char *)zlib__ZlibDecompressor__doc__},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something separate, but I think AC should give the possibility to create docstrings for class and module directives as well.

{Py_tp_methods, ZlibDecompressor_methods},
{0, 0},
};
Expand Down
Loading