d.foo = 1
verify(d.foo == 1)
+ # Test handling of int*seq and seq*int
+ class I(int):
+ __dynamic__ = 1
+ verify("a"*I(2) == "aa")
+ verify(I(2)*"a" == "aa")
+
+ # Test handling of long*seq and seq*long
+ class L(long):
+ __dynamic__ = 1
+ verify("a"*L(2L) == "aa")
+ verify(L(2L)*"a" == "aa")
+
+
def errors():
if verbose: print "Testing errors..."
long a, b, ah, bh, x, y;
int s = 1;
- if (v->ob_type->tp_as_sequence &&
- v->ob_type->tp_as_sequence->sq_repeat) {
+ if (!PyInt_Check(v) &&
+ v->ob_type->tp_as_sequence &&
+ v->ob_type->tp_as_sequence->sq_repeat) {
/* sequence * int */
a = PyInt_AsLong(w);
return (*v->ob_type->tp_as_sequence->sq_repeat)(v, a);
}
- else if (w->ob_type->tp_as_sequence &&
- w->ob_type->tp_as_sequence->sq_repeat) {
+ if (!PyInt_Check(w) &&
+ w->ob_type->tp_as_sequence &&
+ w->ob_type->tp_as_sequence->sq_repeat) {
/* int * sequence */
a = PyInt_AsLong(v);
return (*w->ob_type->tp_as_sequence->sq_repeat)(w, a);
int i, sign;
if (vv == NULL || !PyLong_Check(vv)) {
+ if (vv != NULL && PyInt_Check(vv))
+ return PyInt_AsLong(vv);
PyErr_BadInternalCall();
return -1;
}
int size_a;
int size_b;
int i;
-
- if (v->ob_type->tp_as_sequence &&
- v->ob_type->tp_as_sequence->sq_repeat) {
- return long_repeat((PyObject *)v, w);
- }
- else if (w->ob_type->tp_as_sequence &&
- w->ob_type->tp_as_sequence->sq_repeat) {
- return long_repeat((PyObject *)w, v);
- }
- CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b);
+ if (!convert_binop((PyObject *)v, (PyObject *)w, &a, &b)) {
+ if (!PyLong_Check(v) &&
+ v->ob_type->tp_as_sequence &&
+ v->ob_type->tp_as_sequence->sq_repeat)
+ return long_repeat((PyObject *)v, w);
+ if (!PyLong_Check(w) &&
+ w->ob_type->tp_as_sequence &&
+ w->ob_type->tp_as_sequence->sq_repeat)
+ return long_repeat((PyObject *)w, v);
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
size_a = ABS(a->ob_size);
size_b = ABS(b->ob_size);