mirror of
https://github.com/python/cpython.git
synced 2025-11-27 13:45:25 +00:00
SF bug 544647.
PyNumber_InPlaceMultiply insisted on calling sq_inplace_repeat if it existed, even if nb_inplace_multiply also existed and the arguments weren't right for sq_inplace_repeat. Change this to only use sq_inplace_repeat if nb_inplace_multiply isn't defined. Bugfix candidate.
This commit is contained in:
parent
7766091e04
commit
e8fc640349
2 changed files with 33 additions and 2 deletions
|
|
@ -2929,6 +2929,32 @@ def funnynew():
|
||||||
vereq(isinstance(d, D), True)
|
vereq(isinstance(d, D), True)
|
||||||
vereq(d.foo, 1)
|
vereq(d.foo, 1)
|
||||||
|
|
||||||
|
def imulbug():
|
||||||
|
# SF bug 544647
|
||||||
|
if verbose: print "Testing for __imul__ problems..."
|
||||||
|
class C(object):
|
||||||
|
def __imul__(self, other):
|
||||||
|
return (self, other)
|
||||||
|
x = C()
|
||||||
|
y = x
|
||||||
|
y *= 1.0
|
||||||
|
vereq(y, (x, 1.0))
|
||||||
|
y = x
|
||||||
|
y *= 2
|
||||||
|
vereq(y, (x, 2))
|
||||||
|
y = x
|
||||||
|
y *= 3L
|
||||||
|
vereq(y, (x, 3L))
|
||||||
|
y = x
|
||||||
|
y *= 1L<<100
|
||||||
|
vereq(y, (x, 1L<<100))
|
||||||
|
y = x
|
||||||
|
y *= None
|
||||||
|
vereq(y, (x, None))
|
||||||
|
y = x
|
||||||
|
y *= "foo"
|
||||||
|
vereq(y, (x, "foo"))
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
class_docstrings()
|
class_docstrings()
|
||||||
lists()
|
lists()
|
||||||
|
|
@ -2992,6 +3018,7 @@ def test_main():
|
||||||
dictproxyiteritems()
|
dictproxyiteritems()
|
||||||
pickleslots()
|
pickleslots()
|
||||||
funnynew()
|
funnynew()
|
||||||
|
imulbug()
|
||||||
if verbose: print "All OK"
|
if verbose: print "All OK"
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -742,8 +742,12 @@ PyObject *
|
||||||
PyNumber_InPlaceMultiply(PyObject *v, PyObject *w)
|
PyNumber_InPlaceMultiply(PyObject *v, PyObject *w)
|
||||||
{
|
{
|
||||||
PyObject * (*g)(PyObject *, int) = NULL;
|
PyObject * (*g)(PyObject *, int) = NULL;
|
||||||
if (HASINPLACE(v) && v->ob_type->tp_as_sequence &&
|
if (HASINPLACE(v) &&
|
||||||
(g = v->ob_type->tp_as_sequence->sq_inplace_repeat)) {
|
v->ob_type->tp_as_sequence &&
|
||||||
|
(g = v->ob_type->tp_as_sequence->sq_inplace_repeat) &&
|
||||||
|
!(v->ob_type->tp_as_number &&
|
||||||
|
v->ob_type->tp_as_number->nb_inplace_multiply))
|
||||||
|
{
|
||||||
long n;
|
long n;
|
||||||
if (PyInt_Check(w)) {
|
if (PyInt_Check(w)) {
|
||||||
n = PyInt_AsLong(w);
|
n = PyInt_AsLong(w);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue