]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-132983: Slightly tweak error messages for _zstd compressor/decompressor options...
authorEmma Smith <emma@emmatyping.dev>
Fri, 23 May 2025 21:51:41 +0000 (14:51 -0700)
committerGitHub <noreply@github.com>
Fri, 23 May 2025 21:51:41 +0000 (14:51 -0700)
Slightly tweak error messages for options dict

Lib/test/test_zstd.py
Modules/_zstd/compressor.c
Modules/_zstd/decompressor.c

index 084f8f24fc009c89a70e5de1454f7f3b5cc714cf..34c7c721b1ad3269821de171d4f1ab4e2b47e64a 100644 (file)
@@ -1424,11 +1424,12 @@ class FileTestCase(unittest.TestCase):
         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 DecompressionParameter"):
             ZstdFile(io.BytesIO(), 'wb',
                      options={DecompressionParameter.window_log_max:21})
 
index 8f934858ef784f5edc25ae52d9d3b5be85455cf9..0f2967b60555a5eade18e6bcecea39cae72681b2 100644 (file)
@@ -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;
             }
 
index e299f73b071353cfa742243c4f7468cd6acdddcd..70848d98534fa54e33602d27441783e5946c21a8 100644 (file)
@@ -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,