Skip to content

Commit 09ff114

Browse files
[3.14] gh-150285: Fix too long docstrings in the zstd module (GH-150291) (GH-150335) (#150421)
(cherry picked from commit 9fceb1c) (cherry picked from commit d3e2a13) Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
1 parent 11a02aa commit 09ff114

8 files changed

Lines changed: 139 additions & 126 deletions

File tree

Lib/compression/zstd/__init__.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ def __setattr__(self, name, _):
6161
def get_frame_info(frame_buffer):
6262
"""Get Zstandard frame information from a frame header.
6363
64-
*frame_buffer* is a bytes-like object. It should start from the beginning
65-
of a frame, and needs to include at least the frame header (6 to 18 bytes).
64+
*frame_buffer* is a bytes-like object. It should start from the
65+
beginning of a frame, and needs to include at least the frame header
66+
(6 to 18 bytes).
6667
6768
The returned FrameInfo object has two attributes.
6869
'decompressed_size' is the size in bytes of the data in the frame when
@@ -103,16 +104,17 @@ def finalize_dict(zstd_dict, /, samples, dict_size, level):
103104
finalize *zstd_dict* by adding headers and statistics according to the
104105
Zstandard dictionary format.
105106
106-
You may compose an effective dictionary content by hand, which is used as
107-
basis dictionary, and use some samples to finalize a dictionary. The basis
108-
dictionary may be a "raw content" dictionary. See *is_raw* in ZstdDict.
107+
You may compose an effective dictionary content by hand, which is used
108+
as basis dictionary, and use some samples to finalize a dictionary. The
109+
basis dictionary may be a "raw content" dictionary. See *is_raw* in
110+
ZstdDict.
109111
110-
*samples* is an iterable of samples, where a sample is a bytes-like object
111-
representing a file.
112+
*samples* is an iterable of samples, where a sample is a bytes-like
113+
object representing a file.
112114
*dict_size* is the dictionary's maximum size, in bytes.
113115
*level* is the expected compression level. The statistics for each
114-
compression level differ, so tuning the dictionary to the compression level
115-
can provide improvements.
116+
compression level differ, so tuning the dictionary to the compression
117+
level can provide improvements.
116118
"""
117119

118120
if not isinstance(zstd_dict, ZstdDict):
@@ -140,8 +142,8 @@ def compress(data, level=None, options=None, zstd_dict=None):
140142
COMPRESSION_LEVEL_DEFAULT ('3').
141143
*options* is a dict object that contains advanced compression
142144
parameters. See CompressionParameter for more on options.
143-
*zstd_dict* is a ZstdDict object, a pre-trained Zstandard dictionary. See
144-
the function train_dict for how to train a ZstdDict on sample data.
145+
*zstd_dict* is a ZstdDict object, a pre-trained Zstandard dictionary.
146+
See the function train_dict for how to train a ZstdDict on sample data.
145147
146148
For incremental compression, use a ZstdCompressor instead.
147149
"""
@@ -152,8 +154,8 @@ def compress(data, level=None, options=None, zstd_dict=None):
152154
def decompress(data, zstd_dict=None, options=None):
153155
"""Decompress one or more frames of Zstandard compressed *data*.
154156
155-
*zstd_dict* is a ZstdDict object, a pre-trained Zstandard dictionary. See
156-
the function train_dict for how to train a ZstdDict on sample data.
157+
*zstd_dict* is a ZstdDict object, a pre-trained Zstandard dictionary.
158+
See the function train_dict for how to train a ZstdDict on sample data.
157159
*options* is a dict object that contains advanced compression
158160
parameters. See DecompressionParameter for more on options.
159161

Lib/compression/zstd/_zstdfile.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def __init__(self, file, /, mode='r', *,
3636
3737
*file* can be either an file-like object, or a file name to open.
3838
39-
*mode* can be 'r' for reading (default), 'w' for (over)writing, 'x' for
40-
creating exclusively, or 'a' for appending. These can equivalently be
41-
given as 'rb', 'wb', 'xb' and 'ab' respectively.
39+
*mode* can be 'r' for reading (default), 'w' for (over)writing, 'x'
40+
for creating exclusively, or 'a' for appending. These can
41+
equivalently be given as 'rb', 'wb', 'xb' and 'ab' respectively.
4242
4343
*level* is an optional int specifying the compression level to use,
4444
or COMPRESSION_LEVEL_DEFAULT if not given.
@@ -296,26 +296,27 @@ def open(file, /, mode='rb', *, level=None, options=None, zstd_dict=None,
296296
encoding=None, errors=None, newline=None):
297297
"""Open a Zstandard compressed file in binary or text mode.
298298
299-
file can be either a file name (given as a str, bytes, or PathLike object),
300-
in which case the named file is opened, or it can be an existing file object
301-
to read from or write to.
299+
file can be either a file name (given as a str, bytes, or PathLike
300+
object), in which case the named file is opened, or it can be
301+
an existing file object to read from or write to.
302302
303-
The mode parameter can be 'r', 'rb' (default), 'w', 'wb', 'x', 'xb', 'a',
304-
'ab' for binary mode, or 'rt', 'wt', 'xt', 'at' for text mode.
303+
The mode parameter can be 'r', 'rb' (default), 'w', 'wb', 'x', 'xb',
304+
'a', 'ab' for binary mode, or 'rt', 'wt', 'xt', 'at' for text mode.
305305
306-
The level, options, and zstd_dict parameters specify the settings the same
307-
as ZstdFile.
306+
The level, options, and zstd_dict parameters specify the settings the
307+
same as ZstdFile.
308308
309309
When using read mode (decompression), the options parameter is a dict
310-
representing advanced decompression options. The level parameter is not
311-
supported in this case. When using write mode (compression), only one of
312-
level, an int representing the compression level, or options, a dict
313-
representing advanced compression options, may be passed. In both modes,
314-
zstd_dict is a ZstdDict instance containing a trained Zstandard dictionary.
315-
316-
For binary mode, this function is equivalent to the ZstdFile constructor:
317-
ZstdFile(filename, mode, ...). In this case, the encoding, errors and
318-
newline parameters must not be provided.
310+
representing advanced decompression options. The level parameter is not
311+
supported in this case. When using write mode (compression), only one
312+
of level, an int representing the compression level, or options, a dict
313+
representing advanced compression options, may be passed. In both
314+
modes, zstd_dict is a ZstdDict instance containing a trained Zstandard
315+
dictionary.
316+
317+
For binary mode, this function is equivalent to the ZstdFile
318+
constructor: ZstdFile(filename, mode, ...). In this case, the encoding,
319+
errors and newline parameters must not be provided.
319320
320321
For text mode, an ZstdFile object is created, and wrapped in an
321322
io.TextIOWrapper instance with the specified encoding, error handling

Modules/_zstd/clinic/compressor.c.h

Lines changed: 16 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_zstd/clinic/decompressor.c.h

Lines changed: 16 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_zstd/clinic/zstddict.c.h

Lines changed: 16 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_zstd/compressor.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,14 @@ _zstd.ZstdCompressor.__new__ as _zstd_ZstdCompressor_new
332332
333333
Create a compressor object for compressing data incrementally.
334334
335-
Thread-safe at method level. For one-shot compression, use the compress()
336-
function instead.
335+
Thread-safe at method level. For one-shot compression, use the
336+
compress() function instead.
337337
[clinic start generated code]*/
338338

339339
static PyObject *
340340
_zstd_ZstdCompressor_new_impl(PyTypeObject *type, PyObject *level,
341341
PyObject *options, PyObject *zstd_dict)
342-
/*[clinic end generated code: output=cdef61eafecac3d7 input=92de0211ae20ffdc]*/
342+
/*[clinic end generated code: output=cdef61eafecac3d7 input=bbfeeaa06fd3bd4d]*/
343343
{
344344
ZstdCompressor* self = PyObject_GC_New(ZstdCompressor, type);
345345
if (self == NULL) {
@@ -592,15 +592,15 @@ _zstd.ZstdCompressor.compress
592592
593593
Provide data to the compressor object.
594594
595-
Return a chunk of compressed data if possible, or b'' otherwise. When you have
596-
finished providing data to the compressor, call the flush() method to finish
597-
the compression process.
595+
Return a chunk of compressed data if possible, or b'' otherwise.
596+
When you have finished providing data to the compressor, call the
597+
flush() method to finish the compression process.
598598
[clinic start generated code]*/
599599

600600
static PyObject *
601601
_zstd_ZstdCompressor_compress_impl(ZstdCompressor *self, Py_buffer *data,
602602
int mode)
603-
/*[clinic end generated code: output=ed7982d1cf7b4f98 input=ac2c21d180f579ea]*/
603+
/*[clinic end generated code: output=ed7982d1cf7b4f98 input=11726dff64d7b2f9]*/
604604
{
605605
PyObject *ret;
606606

@@ -650,14 +650,14 @@ _zstd.ZstdCompressor.flush
650650
651651
Finish the compression process.
652652
653-
Flush any remaining data left in internal buffers. Since Zstandard data
654-
consists of one or more independent frames, the compressor object can still
655-
be used after this method is called.
653+
Flush any remaining data left in internal buffers. Since Zstandard
654+
data consists of one or more independent frames, the compressor
655+
object can still be used after this method is called.
656656
[clinic start generated code]*/
657657

658658
static PyObject *
659659
_zstd_ZstdCompressor_flush_impl(ZstdCompressor *self, int mode)
660-
/*[clinic end generated code: output=b7cf2c8d64dcf2e3 input=0ab19627f323cdbc]*/
660+
/*[clinic end generated code: output=b7cf2c8d64dcf2e3 input=130e0b1eddf0f498]*/
661661
{
662662
PyObject *ret;
663663

@@ -699,19 +699,20 @@ _zstd.ZstdCompressor.set_pledged_input_size
699699
700700
Set the uncompressed content size to be written into the frame header.
701701
702-
This method can be used to ensure the header of the frame about to be written
703-
includes the size of the data, unless the CompressionParameter.content_size_flag
704-
is set to False. If last_mode != FLUSH_FRAME, then a RuntimeError is raised.
702+
This method can be used to ensure the header of the frame about to
703+
be written includes the size of the data, unless the
704+
CompressionParameter.content_size_flag is set to False.
705+
If last_mode != FLUSH_FRAME, then a RuntimeError is raised.
705706
706-
It is important to ensure that the pledged data size matches the actual data
707-
size. If they do not match the compressed output data may be corrupted and the
708-
final chunk written may be lost.
707+
It is important to ensure that the pledged data size matches the
708+
actual data size. If they do not match the compressed output data
709+
may be corrupted and the final chunk written may be lost.
709710
[clinic start generated code]*/
710711

711712
static PyObject *
712713
_zstd_ZstdCompressor_set_pledged_input_size_impl(ZstdCompressor *self,
713714
unsigned long long size)
714-
/*[clinic end generated code: output=3a09e55cc0e3b4f9 input=afd8a7d78cff2eb5]*/
715+
/*[clinic end generated code: output=3a09e55cc0e3b4f9 input=d6d1669171af3da4]*/
715716
{
716717
// Error occured while converting argument, should be unreachable
717718
assert(size != ZSTD_CONTENTSIZE_ERROR);

0 commit comments

Comments
 (0)