From 5f9ce957d952ba9765dc5cc7c92c07410b8228e5 Mon Sep 17 00:00:00 2001 From: Jason Madden Date: Tue, 7 Apr 2020 06:10:29 -0500 Subject: [PATCH] The value macros for ints also need to convert OverflowError into TypeError. This only showed up on Windows (because it follows the LLP64 data model). See https://ci.appveyor.com/project/mgedmin/btrees/builds/31998447/job/m3xs7q1d8b4u5u3b --- BTrees/intvaluemacros.h | 16 ++++++++++++++-- BTrees/tests/common.py | 16 ++++++++-------- CHANGES.rst | 4 ++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/BTrees/intvaluemacros.h b/BTrees/intvaluemacros.h index 2af2e58..21e0562 100644 --- a/BTrees/intvaluemacros.h +++ b/BTrees/intvaluemacros.h @@ -29,7 +29,13 @@ #define COPY_VALUE_FROM_ARG(TARGET, ARG, STATUS) \ if (INT_CHECK(ARG)) { \ long vcopy = INT_AS_LONG(ARG); \ - if (PyErr_Occurred()) { (STATUS)=0; (TARGET)=0; } \ + if (PyErr_Occurred()) { \ + if (PyErr_ExceptionMatches(PyExc_OverflowError)) { \ + PyErr_Clear(); \ + PyErr_SetString(PyExc_TypeError, "integer out of range"); \ + } \ + (STATUS)=0; (TARGET)=0; \ + } \ else if ((int)vcopy != vcopy) { \ PyErr_SetString(PyExc_TypeError, "integer out of range"); \ (STATUS)=0; (TARGET)=0; \ @@ -62,7 +68,13 @@ #define COPY_VALUE_FROM_ARG(TARGET, ARG, STATUS) \ if (INT_CHECK(ARG)) { \ long vcopy = INT_AS_LONG(ARG); \ - if (PyErr_Occurred()) { (STATUS)=0; (TARGET)=0; } \ + if (PyErr_Occurred()) { \ + if (PyErr_ExceptionMatches(PyExc_OverflowError)) { \ + PyErr_Clear(); \ + PyErr_SetString(PyExc_TypeError, "integer out of range"); \ + } \ + (STATUS)=0; (TARGET)=0; \ + } \ else if (vcopy < 0) { \ PyErr_SetString(PyExc_TypeError, "can't convert negative value to unsigned int"); \ (STATUS)=0; (TARGET)=0; \ diff --git a/BTrees/tests/common.py b/BTrees/tests/common.py index c40fb1d..0893b22 100644 --- a/BTrees/tests/common.py +++ b/BTrees/tests/common.py @@ -390,7 +390,7 @@ class NonSub(object): self.assertFalse(issubclass(NonSub, type(t))) self.assertFalse(isinstance(NonSub(), type(t))) -class MappingBase(Base): +class MappingBase(Base): # pylint:disable=too-many-public-methods # Tests common to mappings (buckets, btrees) SUPPORTS_NEGATIVE_VALUES = True @@ -722,7 +722,7 @@ def testEmptyRangeSearches(self): self.assertEqual(list(keys), []) self.assertEqual(list(t.iterkeys(max=50, min=200)), []) - def testSlicing(self): + def testSlicing(self): # pylint:disable=too-many-locals # Test that slicing of .keys()/.values()/.items() works exactly the # same way as slicing a Python list with the same contents. # This tests fixes to several bugs in this area, starting with @@ -832,7 +832,7 @@ def testIterators(self): self.assertEqual(list(t.iteritems()), list(t.items())) @uses_negative_keys_and_values - def testRangedIterators(self): + def testRangedIterators(self): # pylint:disable=too-many-locals t = self._makeOne() for keys in [], [-2], [1, 4], list(range(-170, 2000, 13)): @@ -1074,7 +1074,6 @@ def testKeyAndValueOverflow(self): self.skipTest("Needs bounded key and value") import struct - from .._compat import PY2 good = set() b = self._makeOne() @@ -1995,7 +1994,7 @@ class ModuleTest(object): key_type = None value_type = None def _getModule(self): - pass + raise NotImplementedError def testNames(self): names = ['Bucket', 'BTree', 'Set', 'TreeSet'] @@ -2223,8 +2222,8 @@ def setUp(self): super(SetResult, self).setUp() _skip_if_pure_py_and_py_test(self) - self.Akeys = [1, 3, 5, 6] - self.Bkeys = [ 2, 3, 4, 6, 7] + self.Akeys = [1, 3, 5, 6] # pylint:disable=bad-whitespace + self.Bkeys = [ 2, 3, 4, 6, 7] # pylint:disable=bad-whitespace self.As = [makeset(self.Akeys) for makeset in self.builders()] self.Bs = [makeset(self.Bkeys) for makeset in self.builders()] self.emptys = [makeset() for makeset in self.builders()] @@ -2336,7 +2335,7 @@ def testDifference(self): else: self.assertEqual(list(C), want) - def testLargerInputs(self): + def testLargerInputs(self): # pylint:disable=too-many-locals from BTrees.IIBTree import IISet # pylint:disable=no-name-in-module from random import randint MAXSIZE = 200 @@ -2592,6 +2591,7 @@ class ConflictTestBase(SignedMixin, object): # Tests common to all types: sets, buckets, and BTrees storage = None + db = None def setUp(self): super(ConflictTestBase, self).setUp() diff --git a/CHANGES.rst b/CHANGES.rst index 5101d63..9a1cad5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -15,6 +15,10 @@ expected. See `issue 140 `_. + .. note:: + The unspecified true return values of ``has_key`` + have changed. + 4.7.1 (2020-03-22) ==================