summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorXiang Zhang <angwerzx@126.com>2017-03-01 14:28:14 +0800
committerGitHub <noreply@github.com>2017-03-01 14:28:14 +0800
commitb4f0e980b6084e9a994e3f069269fac2471e0d78 (patch)
treee0d0caf20efb7485f14226215fc035d86271fc46 /Python
parent02eb4b0bd4a7d86cf5e40567aaa8710b00e079a4 (diff)
downloadcpython-git-b4f0e980b6084e9a994e3f069269fac2471e0d78.tar.gz
bpo-28598: Support __rmod__ for RHS subclasses of str in % string formatting operations (GH-366)
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 2af78ff874..733f0776ec 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1446,10 +1446,14 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
{
w = POP();
v = TOP();
- if (PyString_CheckExact(v))
+ if (PyString_CheckExact(v)
+ && (!PyString_Check(w) || PyString_CheckExact(w))) {
+ /* fast path; string formatting, but not if the RHS is a str subclass
+ (see issue28598) */
x = PyString_Format(v, w);
- else
+ } else {
x = PyNumber_Remainder(v, w);
+ }
Py_DECREF(v);
Py_DECREF(w);
SET_TOP(x);