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

Skip to content

Commit 1991ddc

Browse files
committed
Make multiplying a sequence by a long integer (5L * 'b') legal
1 parent a46fb38 commit 1991ddc

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Objects/abstract.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,21 @@ PyNumber_Multiply(v, w)
384384
}
385385
m = tp->tp_as_sequence;
386386
if (m && m->sq_repeat) {
387-
if (!PyInt_Check(w))
387+
long mul_value;
388+
389+
if (PyInt_Check(w)) {
390+
mul_value = PyInt_AsLong(w);
391+
}
392+
else if (PyLong_Check(w)) {
393+
mul_value = PyLong_AsLong(w);
394+
if (PyErr_Occurred())
395+
return NULL;
396+
}
397+
else {
388398
return type_error(
389399
"can't multiply sequence with non-int");
390-
return (*m->sq_repeat)(v, (int)PyInt_AsLong(w));
400+
}
401+
return (*m->sq_repeat)(v, (int)mul_value);
391402
}
392403
return type_error("bad operand type(s) for *");
393404
}

0 commit comments

Comments
 (0)