diff options
author | Benjamin Peterson <benjamin@python.org> | 2013-03-24 03:32:34 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2013-03-24 03:32:34 (GMT) |
commit | bc1d9c99630cff1b812d27f251f2fa69387d4379 (patch) | |
tree | 73f02e812baab3269040a68361a510ceae18791f | |
parent | ac982d752d0b5069835ddacf5a046cb9647a9dec (diff) | |
parent | da2c7ebd234fc904f6d6de2191eb5f72e8992c95 (diff) | |
download | cpython-bc1d9c99630cff1b812d27f251f2fa69387d4379.zip cpython-bc1d9c99630cff1b812d27f251f2fa69387d4379.tar.gz cpython-bc1d9c99630cff1b812d27f251f2fa69387d4379.tar.bz2 |
merge 2.7.4 release branch
-rw-r--r-- | Lib/test/string_tests.py | 4 | ||||
-rw-r--r-- | Misc/NEWS | 7 | ||||
-rw-r--r-- | Objects/stringobject.c | 4 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 4 |
4 files changed, 15 insertions, 4 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index d3412d0..d5ab6ae 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -1130,6 +1130,10 @@ class MixinStrUnicodeUserStringTest: class X(object): pass self.checkraises(TypeError, 'abc', '__mod__', X()) + class X(Exception): + def __getitem__(self, k): + return k + self.checkequal('melon apple', '%(melon)s %(apple)s', '__mod__', X()) def test_floatformatting(self): # float formatting @@ -18,6 +18,13 @@ What's New in Python 2.7.4? *Release date: XXXX-XX-XX* +Core and Builtins +----------------- + +- Issue #15801 (again): With string % formatting, relax the type check for a + mapping such that any type with a __getitem__ can be used on the right hand + side. + Library ------- diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 7871323..1209197 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -4257,8 +4257,8 @@ PyString_Format(PyObject *format, PyObject *args) arglen = -1; argidx = -2; } - if (PyMapping_Check(args) && !PyTuple_Check(args) && - !PyObject_TypeCheck(args, &PyBaseString_Type)) + if (Py_TYPE(args)->tp_as_mapping && Py_TYPE(args)->tp_as_mapping->mp_subscript && + !PyTuple_Check(args) && !PyObject_TypeCheck(args, &PyBaseString_Type)) dict = args; while (--fmtcnt >= 0) { if (*fmt != '%') { diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 981a98b..0ead06f 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8287,8 +8287,8 @@ PyObject *PyUnicode_Format(PyObject *format, arglen = -1; argidx = -2; } - if (PyMapping_Check(args) && !PyTuple_Check(args) && - !PyObject_TypeCheck(args, &PyBaseString_Type)) + if (Py_TYPE(args)->tp_as_mapping && Py_TYPE(args)->tp_as_mapping->mp_subscript && + !PyTuple_Check(args) && !PyObject_TypeCheck(args, &PyBaseString_Type)) dict = args; while (--fmtcnt >= 0) { |