Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 28a6cfa

Browse files
committed
use the stricter PyMapping_Check (closes #15801)
1 parent 2412c93 commit 28a6cfa

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/test/string_tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,9 @@ def test_formatting(self):
11421142
self.checkraises(TypeError, '%10.*f', '__mod__', ('foo', 42.))
11431143
self.checkraises(ValueError, '%10', '__mod__', (42,))
11441144

1145+
class X(object): pass
1146+
self.checkraises(TypeError, 'abc', '__mod__', X())
1147+
11451148
def test_floatformatting(self):
11461149
# float formatting
11471150
for prec in range(100):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Core and Builtins
1212

1313
- Issue #15761: Fix crash when PYTHONEXECUTABLE is set on Mac OS X.
1414

15+
- Issue #15801: Make sure mappings passed to '%' formatting are actually
16+
subscriptable.
17+
1518
- Issue #15726: Fix incorrect bounds checking in PyState_FindModule.
1619
Patch by Robin Schreiber.
1720

Objects/unicodeobject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9504,8 +9504,7 @@ PyObject *PyUnicode_Format(PyObject *format,
95049504
arglen = -1;
95059505
argidx = -2;
95069506
}
9507-
if (Py_TYPE(args)->tp_as_mapping && !PyTuple_Check(args) &&
9508-
!PyUnicode_Check(args))
9507+
if (PyMapping_Check(args) && !PyTuple_Check(args) && !PyUnicode_Check(args))
95099508
dict = args;
95109509

95119510
while (--fmtcnt >= 0) {

0 commit comments

Comments
 (0)