Rev 5045: (mbp) clean up exceptions from StaticTuple_New in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Feb 18 01:10:21 GMT 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5045 [merge]
revision-id: pqm at pqm.ubuntu.com-20100218011016-cx9drbdydd2xmu2p
parent: pqm at pqm.ubuntu.com-20100217174203-bd8elqnhq6w48xb2
parent: mnordhoff at mattnordhoff.com-20091022082804-outyhrw2y14fxt4x
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2010-02-18 01:10:16 +0000
message:
(mbp) clean up exceptions from StaticTuple_New
modified:
bzrlib/_static_tuple_c.c _keys_type_c.c-20090908204220-aa346ccw4l37jzt7-1
bzrlib/_static_tuple_py.py _keys_type_py.py-20090908213415-o1ww98k9a8aqm0bm-1
bzrlib/tests/test__static_tuple.py test__keys_type.py-20090908204220-aa346ccw4l37jzt7-2
=== modified file 'bzrlib/_static_tuple_c.c'
--- a/bzrlib/_static_tuple_c.c 2009-10-27 14:07:16 +0000
+++ b/bzrlib/_static_tuple_c.c 2010-02-18 01:10:16 +0000
@@ -140,10 +140,6 @@
StaticTuple_New(Py_ssize_t size)
{
StaticTuple *stuple;
- if (size < 0) {
- PyErr_BadInternalCall();
- return NULL;
- }
if (size < 0 || size > 255) {
/* Too big or too small */
@@ -280,6 +276,14 @@
return NULL;
}
len = PyTuple_GET_SIZE(args);
+ if (len < 0 || len > 255) {
+ /* Check the length here so we can raise a TypeError instead of
+ * StaticTuple_New's ValueError.
+ */
+ PyErr_SetString(PyExc_TypeError, "StaticTuple(...)"
+ " takes from 0 to 255 items");
+ return NULL;
+ }
self = (StaticTuple *)StaticTuple_New(len);
if (self == NULL) {
return NULL;
=== modified file 'bzrlib/_static_tuple_py.py'
--- a/bzrlib/_static_tuple_py.py 2009-11-28 21:54:08 +0000
+++ b/bzrlib/_static_tuple_py.py 2010-02-18 01:10:16 +0000
@@ -34,15 +34,15 @@
def __init__(self, *args):
"""Create a new 'StaticTuple'"""
+ num_keys = len(args)
+ if num_keys < 0 or num_keys > 255:
+ raise TypeError('StaticTuple(...) takes from 0 to 255 items')
for bit in args:
if type(bit) not in (str, StaticTuple, unicode, int, long, float,
None.__class__, bool):
raise TypeError('StaticTuple can only point to'
' StaticTuple, str, unicode, int, long, float, bool, or'
' None not %s' % (type(bit),))
- num_keys = len(args)
- if num_keys < 0 or num_keys > 255:
- raise ValueError('must have 1 => 256 key bits')
# We don't need to pass args to tuple.__init__, because that was
# already handled in __new__.
tuple.__init__(self)
=== modified file 'bzrlib/tests/test__static_tuple.py'
--- a/bzrlib/tests/test__static_tuple.py 2009-12-22 16:28:47 +0000
+++ b/bzrlib/tests/test__static_tuple.py 2010-02-18 01:10:16 +0000
@@ -77,9 +77,9 @@
def test_create_bad_args(self):
args_256 = ['a']*256
# too many args
- self.assertRaises(ValueError, self.module.StaticTuple, *args_256)
+ self.assertRaises(TypeError, self.module.StaticTuple, *args_256)
args_300 = ['a']*300
- self.assertRaises(ValueError, self.module.StaticTuple, *args_300)
+ self.assertRaises(TypeError, self.module.StaticTuple, *args_300)
# not a string
self.assertRaises(TypeError, self.module.StaticTuple, object())
More information about the bazaar-commits
mailing list