8000 gh-132983: Convert zstd __new__ methods to Argument Clinic by AA-Turner · Pull Request #133860 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-132983: Convert zstd __new__ methods to Argument Clinic #133860

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 9 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Consistently use Zstandard vs zstd
  • Loading branch information
AA-Turner committed May 11, 2025
commit 4cc2d4e2111cab9b1855fea854fda79a388edaf6
4 changes: 2 additions & 2 deletions Lib/test/test_zstd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,9 +1072,9 @@ def test_invalid_dict(self):

# corrupted
zd = ZstdDict(dict_content, is_raw=False)
with self.assertRaisesRegex(ZstdError, r'ZSTD_CDict.*?corrupted'):
with self.assertRaisesRegex(ZstdError, r'ZSTD_CDict.*?content\.$'):
ZstdCompressor(zstd_dict=zd.as_digested_dict)
with self.assertRaisesRegex(ZstdError, r'ZSTD_DDict.*?corrupted'):
with self.assertRaisesRegex(ZstdError, r'ZSTD_DDict.*?content\.$'):
ZstdDecompressor(zd)

# wrong type
Expand Down
35 changes: 16 additions & 19 deletions Modules/_zstd/_zstdmodule.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*
Low level interface to Meta's zstd library for use in the compression.zstd
Python module.
*/
/* Low level interface to the Zstandard algorthm & the zstd library. */

#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
Expand Down Expand Up @@ -34,17 +31,17 @@ set_zstd_error(const _zstd_state* const state,
switch (type)
{
case ERR_DECOMPRESS:
msg = "Unable to decompress zstd data: %s";
msg = "Unable to decompress Zstandard data: %s";
break;
case ERR_COMPRESS:
msg = "Unable to compress zstd data: %s";
msg = "Unable to compress Zstandard data: %s";
break;

case ERR_LOAD_D_DICT:
msg = "Unable to load zstd dictionary or prefix for decompression: %s";
msg = "Unable to load Zstandard dictionary or prefix for decompression: %s";
break;
case ERR_LOAD_C_DICT:
msg = "Unable to load zstd dictionary or prefix for compression: %s";
msg = "Unable to load Zstandard dictionary or prefix for compression: %s";
break;

case ERR_GET_C_BOUNDS:
Expand All @@ -58,10 +55,10 @@ set_zstd_error(const _zstd_state* const state,
break;

case ERR_TRAIN_DICT:
msg = "Unable to train zstd dictionary: %s";
msg = "Unable to train the Zstandard dictionary: %s";
break;
case ERR_FINALIZE_DICT:
msg = "Unable to finalize zstd dictionary: %s";
msg = &qu 8000 ot;Unable to finalize the Zstandard dictionary: %s";
break;

default:
Expand Down Expand Up @@ -187,13 +184,13 @@ _zstd.train_dict
The size of the dictionary.
/

Internal function, train a zstd dictionary on sample data.
Internal function, train a Zstandard dictionary on sample data.
[clinic start generated code]*/

static PyObject *
_zstd_train_dict_impl(PyObject *module, PyBytesObject *samples_bytes,
PyObject *samples_sizes, Py_ssize_t dict_size)
/*[clinic end generated code: output=8e87fe43935e8f77 input=70fcd8937f2528b6]*/
/*[clinic end generated code: output=8e87fe43935e8f77 input=829e31fbbf3454b0]*/
{
// TODO(emmatyping): The preamble and suffix to this function and _finalize_dict
// are pretty similar. We should see if we can refactor them to share that code.
Expand Down Expand Up @@ -295,15 +292,15 @@ _zstd.finalize_dict
Optimize for a specific zstd compression level, 0 means default.
/

Internal function, finalize a zstd dictionary.
Internal function, finalize a Zstandard dictionary.
[clinic start generated code]*/

static PyObject *
_zstd_finalize_dict_impl(PyObject *module, PyBytesObject *custom_dict_bytes,
PyBytesObject *samples_bytes,
PyObject *samples_sizes, Py_ssize_t dict_size,
int compression_level)
/*[clinic end generated code: output=f91821ba5ae85bda input=130d1508adb55ba1]*/
/*[clinic end generated code: output=f91821ba5ae85bda input=11af97dcc7608059]*/
{
Py_ssize_t chunks_number;
size_t *chunk_sizes = NULL;
Expand Down Expand Up @@ -457,9 +454,9 @@ _zstd_get_frame_size_impl(PyObject *module, Py_buffer *frame_buffer)
if (ZSTD_isError(frame_size)) {
_zstd_state* const mod_state = get_zstd_state(module);
PyErr_Format(mod_state->ZstdError,
"Error when finding the compressed size of a zstd frame. "
"Make sure the frame_buffer argument starts from the "
"beginning of a frame, and its length not less than this "
"Error when finding the compressed size of a Zstandard frame. "
"Ensure the frame_buffer argument starts from the "
"beginning of a frame, and its length is not less than this "
"complete frame. Zstd error message: %s.",
ZSTD_getErrorName(frame_size));
return NULL;
Expand Down Expand Up @@ -494,9 +491,9 @@ _zstd_get_frame_info_impl(PyObject *module, Py_buffer *frame_buffer)
_zstd_state* const mod_state = get_zstd_state(module);
PyErr_SetString(mod_state->ZstdError,
"Error when getting information from the header of "
"a zstd frame. Make sure the frame_buffer argument "
"a Zstandard frame. Ensure the frame_buffer argument "
"starts from the beginning of a frame, and its length "
"not less than the frame header (6~18 bytes).");
"is not less than the frame header (6~18 bytes).");
return NULL;
}

Expand Down
5 changes: 1 addition & 4 deletions Modules/_zstd/_zstdmodule.h
8000
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*
Low level interface to Meta's zstd library for use in the compression.zstd
Python module.
*/
/* Low level interface to the Zstandard algorthm & the zstd library. */

/* Declarations shared between different parts of the _zstd module*/

Expand Down
5 changes: 1 addition & 4 deletions Modules/_zstd/buffer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*
Low level interface to Meta's zstd library for use in the compression.zstd
Python module.
*/
/* Low level interface to the Zstandard algorthm & the zstd library. */

#ifndef ZSTD_BUFFER_H
#define ZSTD_BUFFER_H
Expand Down
6 changes: 3 additions & 3 deletions Modules/_zstd/clinic/_zstdmodule.c.h

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

9 changes: 3 additions & 6 deletions Modules/_zstd/compressor.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*
Low level interface to Meta's zstd library for use in the compression.zstd
Python module.
*/
/* Low level interface to the Zstandard algorthm & the zstd library. */

/* ZstdCompressor class definitions */

Expand Down Expand Up @@ -186,8 +183,8 @@ _get_CDict(ZstdDict *self, int compressionLevel)
_zstd_state* const mod_state = PyType_GetModuleState(Py_TYPE(self));
if (mod_state != NULL) {
PyErr_SetString(mod_state->ZstdError,
"Failed to create ZSTD_CDict instance from zstd "
"dictionary content. Maybe the content is corrupted.");
"Failed to create a ZSTD_CDict instance from "
"Zstandard dictionary content.");
}
goto error;
}
Expand Down
11 changes: 4 additions & 7 deletions Modules/_zstd/decompressor.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*
Low level interface to Meta's zstd library for use in the compression.zstd
Python module.
*/
/* Low level interface to the Zstandard algorthm & the zstd library. */

/* ZstdDecompressor class definition */

Expand Down Expand Up @@ -78,8 +75,8 @@ _get_DDict(ZstdDict *self)
_zstd_state* const mod_state = PyType_GetModuleState(Py_TYPE(self));
if (mod_state != NULL) {
PyErr_SetString(mod_state->ZstdError,
"Failed to create ZSTD_DDict instance from zstd "
"dictionary content. Maybe the content is corrupted.");
"Failed to create a ZSTD_DDict instance from "
"Zstandard dictionary content.");
}
}
}
Expand Down Expand Up @@ -370,7 +367,7 @@ stream_decompress(ZstdDecompressor *self, Py_buffer *data, Py_ssize_t max_length

/* Check .eof flag */
if (self->eof) {
PyErr_SetString(PyExc_EOFError, "Already at the end of a zstd frame.");
PyErr_SetString(PyExc_EOFError, "Already at the end of a Zstandard frame.");
assert(ret == NULL);
return NULL;
}
Expand Down
22 changes: 8 additions & 14 deletions Modules/_zstd/zstddict.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*
Low level interface to Meta's zstd library for use in the compression.zstd
Python module.
*/
/* Low level interface to the Zstandard algorthm & the zstd library. */

/* ZstdDict class definitions */

Expand Down Expand Up @@ -84,9 +81,7 @@ _zstd_ZstdDict_new_impl(PyTypeObject *type, PyObject *dict_content,

/* Check validity for ordinary dictionary */
if (!is_raw && self->dict_id == 0) {
char *msg = "The dict_content argument is not a valid zstd "
"dictionary. The first 4 bytes of a valid zstd dictionary "
"should be a magic number: b'\\x37\\xA4\\x30\\xEC'.\n";
char *msg = "Invalid Zstandard dictionary and is_raw not set.\n";
PyErr_SetString(PyExc_ValueError, msg);
goto error;
}
Expand Down Expand Up @@ -123,15 +118,14 @@ ZstdDict_dealloc(PyObject *ob)
}

PyDoc_STRVAR(ZstdDict_dictid_doc,
"ID of zstd dictionary, a 32-bit unsigned int value.\n\n"
"Non-zero means ordinary dictionary, was created by zstd functions, follow\n"
"a specified format.\n\n"
"0 means a \"raw content\" dictionary, free of any format restriction, used\n"
"for advanced user.");
"The ID of Zstandard dictionary, an integer between 0 and 2**32.\n\n"
"A non-zero value represents an ordinary Zstandard dictionary, "
"conforming to the standardised format.\n\n"
"The special value '0' means a 'raw content' dictionary,"
"without any restrictions on format or content.");

PyDoc_STRVAR(ZstdDict_dictcontent_doc,
"The content of zstd dictionary, a bytes object, it's the same as dict_content\n"
"argument in ZstdDict.__init__() method. It can be used with other programs.");
"The content of a Zstandard dictionary, as a bytes object.");

static PyObject *
ZstdDict_str(PyObject *ob)
Expand Down
5 changes: 1 addition & 4 deletions Modules/_zstd/zstddict.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*
Low level interface to Meta's zstd library for use in the compression.zstd
Python module.
*/
/* Low level interface to the Zstandard algorthm & the zstd library. */

#ifndef ZSTD_DICT_H
#define ZSTD_DICT_H
Expand Down
Loading
0