self.assertRaises(TypeError, '{a'.format_map)
self.assertRaises(TypeError, '}a'.format_map)
+ # issue #12579: can't supply positional params to format_map
+ self.assertRaises(ValueError, '{}'.format_map, {'a' : 2})
+ self.assertRaises(ValueError, '{}'.format_map, 'a')
+ self.assertRaises(ValueError, '{a} {}'.format_map, {"a" : 2, "b" : 1})
+
def test_format_auto_numbering(self):
class C:
def __init__(self, x=100):
Core and Builtins
-----------------
+- Issue #12579: str.format_map() now raises a ValueError if used on a
+ format string that contains positional fields. Initial patch by
+ Julian Berman.
+
- Issue #11627: Fix segfault when __new__ on a exception returns a non-exception
class.
Py_DECREF(key);
}
else {
+ /* If args is NULL, we have a format string with a positional field
+ with only kwargs to retrieve it from. This can only happen when
+ used with format_map(), where positional arguments are not
+ allowed. */
+ if (args == NULL) {
+ PyErr_SetString(PyExc_ValueError, "Format string contains "
+ "positional fields");
+ goto error;
+ }
+
/* look up in args */
obj = PySequence_GetItem(args, index);
if (obj == NULL)