[Python-checkins] r54193 - sandbox/trunk/pep3101/test_simpleformat.py sandbox/trunk/pep3101/unicodeformat.c
patrick.maupin
python-checkins at python.org
Wed Mar 7 05:46:28 CET 2007
Author: patrick.maupin
Date: Wed Mar 7 05:46:21 2007
New Revision: 54193
Modified:
sandbox/trunk/pep3101/test_simpleformat.py
sandbox/trunk/pep3101/unicodeformat.c
Log:
Found/fixed bug with useall and no keyword dictionary
Modified: sandbox/trunk/pep3101/test_simpleformat.py
==============================================================================
--- sandbox/trunk/pep3101/test_simpleformat.py (original)
+++ sandbox/trunk/pep3101/test_simpleformat.py Wed Mar 7 05:46:21 2007
@@ -350,6 +350,8 @@
self.formatEquals(result, s, 'a', 'b', bar=bar, foo=1)
self.formatEquals(result, s, 'a', 'b', bar=bar, foo=1, sam=27)
self.formatRaises(ValueError, s2, 'a', 'b', bar=bar, foo=1, sam=27)
+ self.formatRaises(ValueError, '{!useall}', 1)
+ self.formatRaises(ValueError, '{!useall}', foo=1)
def test_comments(self):
self.formatEquals('Hi there','''{#Comment}Hi{#
Modified: sandbox/trunk/pep3101/unicodeformat.c
==============================================================================
--- sandbox/trunk/pep3101/unicodeformat.c (original)
+++ sandbox/trunk/pep3101/unicodeformat.c Wed Mar 7 05:46:21 2007
@@ -2113,7 +2113,7 @@
PyObject *used = fs->keyword_arg_set;
if (result != NULL) {
num_unused = fs->positional_arg_set;
- if (!num_unused) {
+ if (!num_unused && (used != NULL)) {
num_unused = PySet_GET_SIZE(used);
i = 0;
while (num_unused && (ignore[i] != NULL)) {
@@ -2132,7 +2132,7 @@
result = SetError(fs, "Not all arguments consumed");
}
}
- Py_DECREF(used);
+ Py_XDECREF(used);
return result;
}
@@ -2151,12 +2151,16 @@
fs.max_recursion = 4;
fs.do_markup = do_markup;
+ /* XXX -- I really want to say fs.keywords = keywords,
+ but this exposes a different set of potential bugs... */
+ fs.keywords = (keywords != NULL && PyDict_Size(keywords))
+ ? keywords : NULL;
fs.keywords = keywords;
result = build_string(&fs);
Py_XDECREF(fs.keywords_tuple);
Py_XDECREF(fs.hookfunc);
- return (fs.keyword_arg_set != NULL)
+ return ((fs.keyword_arg_set != NULL) || fs.positional_arg_set)
? check_args_consumed(&fs, result)
: result;
}
More information about the Python-checkins
mailing list