[Python-checkins] cpython (2.7): use the stricter PyMapping_Check (closes #15801)
benjamin.peterson
python-checkins at python.org
Wed Aug 29 00:02:26 CEST 2012
http://hg.python.org/cpython/rev/2801bf875a24
changeset: 78792:2801bf875a24
branch: 2.7
parent: 78789:ec4ea40be2f6
user: Benjamin Peterson <benjamin at python.org>
date: Tue Aug 28 17:55:35 2012 -0400
summary:
use the stricter PyMapping_Check (closes #15801)
files:
Lib/test/string_tests.py | 3 +++
Misc/NEWS | 3 +++
Objects/stringobject.c | 2 +-
Objects/unicodeobject.c | 2 +-
4 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -1113,6 +1113,9 @@
self.checkraises(TypeError, '%10.*f', '__mod__', ('foo', 42.))
self.checkraises(ValueError, '%10', '__mod__', (42,))
+ class X(object): pass
+ self.checkraises(TypeError, 'abc', '__mod__', X())
+
def test_floatformatting(self):
# float formatting
for prec in xrange(100):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@
Core and Builtins
-----------------
+- Issue #15801: Make sure mappings passed to '%' formatting are actually
+ subscriptable.
+
- Issue #15604: Update uses of PyObject_IsTrue() to check for and handle
errors correctly. Patch by Serhiy Storchaka.
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -4254,7 +4254,7 @@
arglen = -1;
argidx = -2;
}
- if (Py_TYPE(args)->tp_as_mapping && !PyTuple_Check(args) &&
+ if (PyMapping_Check(args) && !PyTuple_Check(args) &&
!PyObject_TypeCheck(args, &PyBaseString_Type))
dict = args;
while (--fmtcnt >= 0) {
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8275,7 +8275,7 @@
arglen = -1;
argidx = -2;
}
- if (Py_TYPE(args)->tp_as_mapping && !PyTuple_Check(args) &&
+ if (PyMapping_Check(args) && !PyTuple_Check(args) &&
!PyObject_TypeCheck(args, &PyBaseString_Type))
dict = args;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list