8000 gh-132983: Slightly tweak error messages for _zstd compressor/decompr… · python/cpython@f478331 · GitHub
[go: up one dir, main page]

Skip to content

Commit f478331

Browse files
authored
gh-132983: Slightly tweak error messages for _zstd compressor/decompressor options dict (#134601)
Slightly tweak error messages for options dict
1 parent 8a793c4 commit f478331

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

Lib/test/test_zstd.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,11 +1424,12 @@ def test_init_bad_mode(self):
14241424
with self.assertRaises(ValueError):
14251425
ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB), "rw")
14261426

1427-
with self.assertRaisesRegex(TypeError, r"NOT be CompressionParameter"):
1427+
with self.assertRaisesRegex(TypeError,
1428+
r"NOT be a CompressionParameter"):
14281429
ZstdFile(io.BytesIO(), 'rb',
14291430
options={CompressionParameter.compression_level:5})
14301431
with self.assertRaisesRegex(TypeError,
1431-
r"NOT be DecompressionParameter"):
1432+
r"NOT be a DecompressionParameter"):
14321433
ZstdFile(io.BytesIO(), 'wb',
14331434
options={DecompressionParameter.window_log_max:21})
14341435

Modules/_zstd/compressor.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,23 @@ _zstd_set_c_parameters(ZstdCompressor *self, PyObject *level_or_options,
9393
/* Check key type */
9494
if (Py_TYPE(key) == mod_state->DParameter_type) {
9595
PyErr_SetString(PyExc_TypeError,
96-
"Key of compression option dict should "
97-
"NOT be DecompressionParameter.");
96+
"Key of compression options dict should "
97+
"NOT be a DecompressionParameter attribute.");
9898
return -1;
9999
}
100100

101101
int key_v = PyLong_AsInt(key);
102102
if (key_v == -1 && PyErr_Occurred()) {
103103
PyErr_SetString(PyExc_ValueError,
104-
"Key of options dict should be a CompressionParameter attribute.");
104+
"Key of options dict should be either a "
105+
"CompressionParameter attribute or an int.");
105106
return -1;
106107
}
107108

108-
// TODO(emmatyping): check bounds when there is a value error here for better
109-
// error message?
110109
int value_v = PyLong_AsInt(value);
111110
if (value_v == -1 && PyErr_Occurred()) {
112111
PyErr_SetString(PyExc_ValueError,
113-
"Value of option dict should be an int.");
112+
"Value of options dict should be an int.");
114113
return -1;
115114
}
116115

Modules/_zstd/decompressor.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,19 @@ _zstd_set_d_parameters(ZstdDecompressor *self, PyObject *options)
112112
if (Py_TYPE(key) == mod_state->CParameter_type) {
113113
PyErr_SetString(PyExc_TypeError,
114114
"Key of decompression options dict should "
115-
"NOT be CompressionParameter.");
115+
"NOT be a CompressionParameter attribute.");
116116
return -1;
117117
}
118118

119119
/* Both key & value should be 32-bit signed int */
120120
int key_v = PyLong_AsInt(key);
121121
if (key_v == -1 && PyErr_Occurred()) {
122122
PyErr_SetString(PyExc_ValueError,
123-
"Key of options dict should be a DecompressionParameter attribute.");
123+
"Key of options dict should be either a "
124+
"DecompressionParameter attribute or an int.");
124125
return -1;
125126
}
126127

127-
// TODO(emmatyping): check bounds when there is a value error here for better
128-
// error message?
129128
int value_v = PyLong_AsInt(value);
130129
if (value_v == -1 && PyErr_Occurred()) {
131130
PyErr_SetString(PyExc_ValueError,

0 commit comments

Comments
 (0)
0