https://github.com/python/cpython/commit/f478331f98930d94f7efc741f3bed4b693d5cec1
commit: f478331f98930d94f7efc741f3bed4b693d5cec1
branch: main
author: Emma Smith <e...@emmatyping.dev>
committer: gpshead <g...@krypto.org>
date: 2025-05-23T14:51:41-07:00
summary:

gh-132983: Slightly tweak error messages for _zstd compressor/decompressor 
options dict (#134601)

Slightly tweak error messages for options dict

files:
M Lib/test/test_zstd.py
M Modules/_zstd/compressor.c
M Modules/_zstd/decompressor.c

diff --git a/Lib/test/test_zstd.py b/Lib/test/test_zstd.py
index 084f8f24fc009c..34c7c721b1ad32 100644
--- a/Lib/test/test_zstd.py
+++ b/Lib/test/test_zstd.py
@@ -1424,11 +1424,12 @@ def test_init_bad_mode(self):
         with self.assertRaises(ValueError):
             ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB), "rw")
 
-        with self.assertRaisesRegex(TypeError, r"NOT be CompressionParameter"):
+        with self.assertRaisesRegex(TypeError,
+                                    r"NOT be a CompressionParameter"):
             ZstdFile(io.BytesIO(), 'rb',
                      options={CompressionParameter.compression_level:5})
         with self.assertRaisesRegex(TypeError,
-                                    r"NOT be DecompressionParameter"):
+                                    r"NOT be a DecompressionParameter"):
             ZstdFile(io.BytesIO(), 'wb',
                      options={DecompressionParameter.window_log_max:21})
 
diff --git a/Modules/_zstd/compressor.c b/Modules/_zstd/compressor.c
index 8f934858ef784f..0f2967b60555a5 100644
--- a/Modules/_zstd/compressor.c
+++ b/Modules/_zstd/compressor.c
@@ -93,24 +93,23 @@ _zstd_set_c_parameters(ZstdCompressor *self, PyObject 
*level_or_options,
             /* Check key type */
             if (Py_TYPE(key) == mod_state->DParameter_type) {
                 PyErr_SetString(PyExc_TypeError,
-                                "Key of compression option dict should "
-                                "NOT be DecompressionParameter.");
+                                "Key of compression options dict should "
+                                "NOT be a DecompressionParameter attribute.");
                 return -1;
             }
 
             int key_v = PyLong_AsInt(key);
             if (key_v == -1 && PyErr_Occurred()) {
                 PyErr_SetString(PyExc_ValueError,
-                                "Key of options dict should be a 
CompressionParameter attribute.");
+                                "Key of options dict should be either a "
+                                "CompressionParameter attribute or an int.");
                 return -1;
             }
 
-            // TODO(emmatyping): check bounds when there is a value error here 
for better
-            // error message?
             int value_v = PyLong_AsInt(value);
             if (value_v == -1 && PyErr_Occurred()) {
                 PyErr_SetString(PyExc_ValueError,
-                                "Value of option dict should be an int.");
+                                "Value of options dict should be an int.");
                 return -1;
             }
 
diff --git a/Modules/_zstd/decompressor.c b/Modules/_zstd/decompressor.c
index e299f73b071353..70848d98534fa5 100644
--- a/Modules/_zstd/decompressor.c
+++ b/Modules/_zstd/decompressor.c
@@ -112,7 +112,7 @@ _zstd_set_d_parameters(ZstdDecompressor *self, PyObject 
*options)
         if (Py_TYPE(key) == mod_state->CParameter_type) {
             PyErr_SetString(PyExc_TypeError,
                             "Key of decompression options dict should "
-                            "NOT be CompressionParameter.");
+                            "NOT be a CompressionParameter attribute.");
             return -1;
         }
 
@@ -120,12 +120,11 @@ _zstd_set_d_parameters(ZstdDecompressor *self, PyObject 
*options)
         int key_v = PyLong_AsInt(key);
         if (key_v == -1 && PyErr_Occurred()) {
             PyErr_SetString(PyExc_ValueError,
-                            "Key of options dict should be a 
DecompressionParameter attribute.");
+                            "Key of options dict should be either a "
+                            "DecompressionParameter attribute or an int.");
             return -1;
         }
 
-        // TODO(emmatyping): check bounds when there is a value error here for 
better
-        // error message?
         int value_v = PyLong_AsInt(value);
         if (value_v == -1 && PyErr_Occurred()) {
             PyErr_SetString(PyExc_ValueError,

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to