summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-08-28 21:55:35 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-08-28 21:55:35 (GMT)
commit28a6cfaefc41a4e4bfa6dd0b54318c0465987652 (patch)
treeb3334773d534a57edf85e637c30e2c07ce53f3b6
parent2412c93a6068221686397c26b129215eac024e9c (diff)
downloadcpython-28a6cfaefc41a4e4bfa6dd0b54318c0465987652.zip
cpython-28a6cfaefc41a4e4bfa6dd0b54318c0465987652.tar.gz
cpython-28a6cfaefc41a4e4bfa6dd0b54318c0465987652.tar.bz2
use the stricter PyMapping_Check (closes #15801)
-rw-r--r--Lib/test/string_tests.py3
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/unicodeobject.c3
3 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index d792529..413f9dd 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -1142,6 +1142,9 @@ class MixinStrUnicodeUserStringTest:
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 range(100):
diff --git a/Misc/NEWS b/Misc/NEWS
index b333c0c..25be2aa 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ Core and Builtins
- Issue #15761: Fix crash when PYTHONEXECUTABLE is set on Mac OS X.
+- Issue #15801: Make sure mappings passed to '%' formatting are actually
+ subscriptable.
+
- Issue #15726: Fix incorrect bounds checking in PyState_FindModule.
Patch by Robin Schreiber.
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index b25b17b..8b782b4 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9504,8 +9504,7 @@ PyObject *PyUnicode_Format(PyObject *format,
arglen = -1;
argidx = -2;
}
- if (Py_TYPE(args)->tp_as_mapping && !PyTuple_Check(args) &&
- !PyUnicode_Check(args))
+ if (PyMapping_Check(args) && !PyTuple_Check(args) && !PyUnicode_Check(args))
dict = args;
while (--fmtcnt >= 0) {