[Python-checkins] cpython: Issue #27474: Unified error messages in the __contains__ method of bytes and

serhiy.storchaka python-checkins at python.org
Sun Jul 10 05:39:04 EDT 2016


https://hg.python.org/cpython/rev/93ab72de7431
changeset:   102293:93ab72de7431
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Jul 10 12:37:30 2016 +0300
summary:
  Issue #27474: Unified error messages in the __contains__ method of bytes and
bytearray for integers in and out of the Py_ssize_t range.
Patch by Xiang Zhang.

files:
  Lib/test/test_bytes.py  |  1 +
  Objects/bytes_methods.c |  2 +-
  2 files changed, 2 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -269,6 +269,7 @@
         self.assertNotIn(200, b)
         self.assertRaises(ValueError, lambda: 300 in b)
         self.assertRaises(ValueError, lambda: -1 in b)
+        self.assertRaises(ValueError, lambda: sys.maxsize+1 in b)
         self.assertRaises(TypeError, lambda: None in b)
         self.assertRaises(TypeError, lambda: float(ord('a')) in b)
         self.assertRaises(TypeError, lambda: "a" in b)
diff --git a/Objects/bytes_methods.c b/Objects/bytes_methods.c
--- a/Objects/bytes_methods.c
+++ b/Objects/bytes_methods.c
@@ -645,7 +645,7 @@
 int
 _Py_bytes_contains(const char *str, Py_ssize_t len, PyObject *arg)
 {
-    Py_ssize_t ival = PyNumber_AsSsize_t(arg, PyExc_ValueError);
+    Py_ssize_t ival = PyNumber_AsSsize_t(arg, NULL);
     if (ival == -1 && PyErr_Occurred()) {
         Py_buffer varg;
         Py_ssize_t pos;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list