diff options
author | Martijn Pieters <github.com@zopatista.com> | 2017-02-27 16:07:27 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2017-02-27 16:07:27 (GMT) |
commit | bc144f0abff2b36595171377ee847c0266596ab2 (patch) | |
tree | 2455d1bd789d8a78d0e1384b8cf6850bed05a914 /Python | |
parent | b945e0784f8b64f9dba41c47844cadf483168a0f (diff) | |
download | cpython-bc144f0abff2b36595171377ee847c0266596ab2.zip cpython-bc144f0abff2b36595171377ee847c0266596ab2.tar.gz cpython-bc144f0abff2b36595171377ee847c0266596ab2.tar.bz2 |
bpo-28598: Support __rmod__ for RHS subclasses of str in % string formatting operations (#94)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 7b40518..d323908 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1545,9 +1545,15 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag) TARGET(BINARY_MODULO) { PyObject *divisor = POP(); PyObject *dividend = TOP(); - PyObject *res = PyUnicode_CheckExact(dividend) ? - PyUnicode_Format(dividend, divisor) : - PyNumber_Remainder(dividend, divisor); + PyObject *res; + if (PyUnicode_CheckExact(dividend) && ( + !PyUnicode_Check(divisor) || PyUnicode_CheckExact(divisor))) { + /* fast path; string formatting, but not if the RHS is a str subclass + (see issue28598) */ + res = PyUnicode_Format(dividend, divisor); + } else { + res = PyNumber_Remainder(dividend, divisor); + } Py_DECREF(divisor); Py_DECREF(dividend); SET_TOP(res); |