Skip to content

Commit ed6d703

Browse files
committed
+1
1 parent 517a029 commit ed6d703

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

Lib/test/test_types.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,9 +2410,6 @@ def test_static_types_inherited_slots(self):
24102410
def collate_results(raw):
24112411
results = {}
24122412
for cls, attr, wrapper in raw:
2413-
if cls is imaginary and slot in ('__abs__', '__bool__',
2414-
'__pow__', '__rpow__'):
2415-
continue
24162413
key = cls, attr
24172414
assert key not in results, (results, key, wrapper)
24182415
results[key] = wrapper
@@ -2431,10 +2428,6 @@ def collate_results(raw):
24312428

24322429
for key, expected in main_results.items():
24332430
cls, attr = key
2434-
if cls == repr(imaginary) and attr in ('__abs__', '__bool__',
2435-
'__pow__', '__rpow__'):
2436-
interp_results.pop(key)
2437-
continue
24382431
with self.subTest(cls=cls, slotattr=attr):
24392432
actual = interp_results.pop(key)
24402433
self.assertEqual(actual, expected)

Objects/complexobject.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,7 @@ imaginary_new_impl(PyTypeObject *type, PyObject *x)
13941394
}
13951395

13961396
PyNumberMethods *nbx = Py_TYPE(x)->tp_as_number;
1397+
13971398
if (nbx == NULL || (nbx->nb_float == NULL && nbx->nb_index == NULL
13981399
&& !PyFloat_Check(x)))
13991400
{
@@ -1404,17 +1405,17 @@ imaginary_new_impl(PyTypeObject *type, PyObject *x)
14041405
}
14051406

14061407
PyObject* tmp = PyNumber_Float(x);
1408+
14071409
if (tmp == NULL) {
14081410
return NULL;
14091411
}
14101412

14111413
PyObject *ret = type->tp_alloc(type, 0);
1414+
14121415
if (ret != NULL) {
14131416
((PyComplexObject *)ret)->cval = (Py_complex) {0.0, PyFloat_AS_DOUBLE(tmp)};
14141417
}
1415-
14161418
Py_DECREF(tmp);
1417-
14181419
return ret;
14191420
}
14201421

@@ -1423,6 +1424,7 @@ PyImaginary_FromDouble(double imag)
14231424
{
14241425
/* Inline PyObject_New */
14251426
PyComplexObject *op = PyObject_Malloc(sizeof(PyComplexObject));
1427+
14261428
if (op == NULL) {
14271429
return PyErr_NoMemory();
14281430
}
@@ -1454,6 +1456,7 @@ imaginary_add(PyObject *v, PyObject *w)
14541456
{
14551457
if (!PyImaginary_Check(v)) {
14561458
PyObject *tmp = v;
1459+
14571460
v = w;
14581461
w = tmp;
14591462
}
@@ -1468,7 +1471,6 @@ imaginary_add(PyObject *v, PyObject *w)
14681471
else if (real_to_double(&w, &b) < 0) {
14691472
return w;
14701473
}
1471-
14721474
return PyComplex_FromDoubles(b, a);
14731475
}
14741476

@@ -1503,7 +1505,6 @@ imaginary_sub(PyObject *v, PyObject *w)
15031505
else if (real_to_double(&w, &b) < 0) {
15041506
return w;
15051507
}
1506-
15071508
return PyComplex_FromDoubles(-b, a);
15081509
}
15091510

@@ -1512,6 +1513,7 @@ imaginary_mul(PyObject *v, PyObject *w)
15121513
{
15131514
if (!PyImaginary_Check(v)) {
15141515
PyObject *tmp = v;
1516+
15151517
v = w;
15161518
w = tmp;
15171519
}
@@ -1530,7 +1532,6 @@ imaginary_mul(PyObject *v, PyObject *w)
15301532
else if (real_to_double(&w, &b) < 0) {
15311533
return w;
15321534
}
1533-
15341535
return PyImaginary_FromDouble(a*b);
15351536
}
15361537

@@ -1544,10 +1545,12 @@ imaginary_div(PyObject *v, PyObject *w)
15441545
if (b) {
15451546
if (PyImaginary_Check(v)) {
15461547
double a = ((PyComplexObject *)(v))->cval.imag;
1548+
15471549
return PyFloat_FromDouble(a/b);
15481550
}
15491551
if (PyComplex_Check(v)) {
15501552
Py_complex a = ((PyComplexObject *)(v))->cval;
1553+
15511554
return PyComplex_FromDoubles(a.imag/b, -a.real/b);
15521555
}
15531556
if (real_to_double(&v, &a) < 0) {
@@ -1562,6 +1565,7 @@ imaginary_div(PyObject *v, PyObject *w)
15621565

15631566
if (PyComplex_Check(w)) {
15641567
Py_complex b = ((PyComplexObject *)(w))->cval;
1568+
15651569
errno = 0;
15661570
b = _Py_rc_quot(a, b);
15671571
b = (Py_complex){-b.imag, b.real};
@@ -1576,7 +1580,6 @@ imaginary_div(PyObject *v, PyObject *w)
15761580
return PyImaginary_FromDouble(a/b);
15771581
}
15781582
}
1579-
15801583
PyErr_SetString(PyExc_ZeroDivisionError, "complex division by zero");
15811584
return NULL;
15821585
}
@@ -1592,6 +1595,7 @@ imaginary_conjugate_impl(PyComplexObject *self)
15921595
/*[clinic end generated code: output=247bb3742efd769d input=8dcd1c93a873c492]*/
15931596
{
15941597
Py_complex c = self->cval;
1598+
15951599
c.imag = -c.imag;
15961600
return PyImaginary_FromDouble(c.imag);
15971601
}
@@ -1606,6 +1610,7 @@ imaginary___getnewargs___impl(PyComplexObject *self)
16061610
/*[clinic end generated code: output=a587156eda821f7d input=da4b7e53915987d5]*/
16071611
{
16081612
Py_complex c = self->cval;
1613+
16091614
return Py_BuildValue("(d)", c.imag);
16101615
}
16111616

0 commit comments

Comments
 (0)