Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf301af6

Browse files
[3.14]gh-132983: Slightly tweak error messages for _zstd compressor/decompressor options dict (GH-134601) (#134602)
gh-132983: Slightly tweak error messages for _zstd compressor/decompressor options dict (GH-134601)Slightly tweak error messages for options dict(cherry picked from commitf478331)Co-authored-by: Emma Smith <emma@emmatyping.dev>
1 parent7476f90 commitf301af6

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
withself.assertRaises(ValueError):
14251425
ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB),"rw")
14261426

1427-
withself.assertRaisesRegex(TypeError,r"NOT be CompressionParameter"):
1427+
withself.assertRaisesRegex(TypeError,
1428+
r"NOT be a CompressionParameter"):
14281429
ZstdFile(io.BytesIO(),'rb',
14291430
options={CompressionParameter.compression_level:5})
14301431
withself.assertRaisesRegex(TypeError,
1431-
r"NOT be DecompressionParameter"):
1432+
r"NOT beaDecompressionParameter"):
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 compressionoption dict should "
97-
"NOT be DecompressionParameter.");
96+
"Key of compressionoptions dict should "
97+
"NOT beaDecompressionParameter attribute.");
9898
return-1;
9999
}
100100

101101
intkey_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
intvalue_v=PyLong_AsInt(value);
111110
if (value_v==-1&&PyErr_Occurred()) {
112111
PyErr_SetString(PyExc_ValueError,
113-
"Value ofoption dict should be an int.");
112+
"Value ofoptions 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 beaCompressionParameter attribute.");
116116
return-1;
117117
}
118118

119119
/* Both key & value should be 32-bit signed int */
120120
intkey_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
intvalue_v=PyLong_AsInt(value);
130129
if (value_v==-1&&PyErr_Occurred()) {
131130
PyErr_SetString(PyExc_ValueError,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp