Skip to content

Commit 53c965b

Browse files
committed
Improve docstrings and formatting
1 parent 29af533 commit 53c965b

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

Lib/compression/zstd/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def train_dict(samples, dict_size):
8989
9090
*samples* is an iterable of samples, where a sample is a bytes-like
9191
object representing a file.
92+
9293
*dict_size* is the dictionary's maximum size, in bytes.
9394
"""
9495
if not isinstance(dict_size, int):
@@ -150,8 +151,10 @@ def compress(data, level=None, options=None, zstd_dict=None):
150151
151152
*level* is an int specifying the compression level to use, defaulting to
152153
COMPRESSION_LEVEL_DEFAULT
154+
153155
*options* is a dict object that contains advanced compression
154156
parameters. See CParameter for more on options.
157+
155158
*zstd_dict* is a ZstdDict object, a pre-trained Zstandard dictionary. See
156159
the function train_dict for how to train a ZstdDict on sample data.
157160
@@ -165,6 +168,7 @@ def decompress(data, zstd_dict=None, options=None):
165168
166169
*zstd_dict* is a ZstdDict object, a pre-trained Zstandard dictionary. See
167170
the function train_dict for how to train a ZstdDict on sample data.
171+
168172
*options* is a dict object that contains advanced compression
169173
parameters. See DParameter for more on options.
170174

Lib/compression/zstd/_zstdfile.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
from os import PathLike
55

6-
from _zstd import ZstdCompressor, ZstdDecompressor, _ZSTD_DStreamSizes, ZstdError
6+
from _zstd import (ZstdCompressor, ZstdDecompressor, _ZSTD_DStreamSizes,
7+
ZstdError)
78
from compression._common import _streams
89

910
__all__ = ("ZstdFile", "open")
@@ -50,13 +51,15 @@ def __init__(
5051
creating exclusively, or "a" for appending. These can equivalently be
5152
given as "rb", "wb", "xb" and "ab" respectively.
5253
53-
Parameters
54-
level: The compression level to use, defaults to ZSTD_CLEVEL_DEFAULT. Note,
55-
in read mode (decompression), compression level is not supported.
56-
options: A dict object, containing advanced compression
57-
parameters.
58-
zstd_dict: A ZstdDict object, pre-trained dictionary for compression /
59-
decompression.
54+
55+
*level* is an int specifying the compression level to use, defaulting to
56+
COMPRESSION_LEVEL_DEFAULT
57+
58+
*options* is a dict object that contains advanced compression
59+
parameters. See CParameter or DParameter for more on options.
60+
61+
*zstd_dict* is a ZstdDict object, a pre-trained Zstandard dictionary.
62+
See the function train_dict for how to train a ZstdDict on sample data.
6063
"""
6164
self._fp = None
6265
self._closefp = False
@@ -68,12 +71,13 @@ def __init__(
6871
raise TypeError(
6972
(
7073
"In read mode (decompression), options argument "
71-
"should be a dict object, that represents decompression "
72-
"options."
74+
"should be a dict object, that represents "
75+
"decompression options."
7376
)
7477
)
7578
if level is not None:
76-
raise TypeError("level argument should only be passed when writing.")
79+
raise TypeError("level argument should only be passed when "
80+
"writing.")
7781
mode_code = _MODE_READ
7882
elif mode in ("w", "wb", "a", "ab", "x", "xb"):
7983
if not isinstance(level, (type(None), int)):
@@ -97,7 +101,8 @@ def __init__(
97101
elif hasattr(filename, "read") or hasattr(filename, "write"):
98102
self._fp = filename
99103
else:
100-
raise TypeError("filename must be a str, bytes, file or PathLike object")
104+
raise TypeError("filename must be a str, bytes, file or PathLike "
105+
"object")
101106
self._mode = mode_code
102107

103108
if self._mode == _MODE_READ:
@@ -137,7 +142,7 @@ def close(self):
137142
self._closefp = False
138143

139144
def write(self, data):
140-
"""Write a bytes-like object to the file.
145+
"""Write a bytes-like object *data* to the file.
141146
142147
Returns the number of uncompressed bytes written, which is
143148
always the length of data in bytes. Note that due to buffering,
@@ -160,7 +165,7 @@ def write(self, data):
160165
def flush(self, mode=FLUSH_BLOCK):
161166
"""Flush remaining data to the underlying stream.
162167
163-
The mode argument can be ZstdFile.FLUSH_BLOCK, ZstdFile.FLUSH_FRAME.
168+
The mode argument can be ZstdFile.FLUSH_BLOCK or ZstdFile.FLUSH_FRAME.
164169
Abuse of this method will reduce compression ratio, use it only when
165170
necessary.
166171

0 commit comments

Comments
 (0)