Skip to content

Commit 2edc777

Browse files
committed
Fix bug in inplace operations for units
1 parent ec7a3bf commit 2edc777

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

tests/test_units.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def test_str_multiply(self):
5252
y = units.Units("hr")
5353
z = x * y
5454
assert str(z) == "hr"
55+
x *= y
56+
assert x == z
5557

5658
@pytest.mark.parametrize('u', [
5759
'invalid'

units.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ static PyObject* do_units_op(PyObject* a, PyObject *b, BinaryOps op,
546546
PyObject* out;
547547
if (inplace) {
548548
out = a;
549+
Py_INCREF(out);
549550
} else {
550551
out = (PyObject*) Units_Type.tp_alloc(&Units_Type, 0);
551552
((UnitsObject*)out)->units = new Units();
@@ -568,9 +569,7 @@ static PyObject* do_units_op(PyObject* a, PyObject *b, BinaryOps op,
568569
break;
569570
}
570571
default: {
571-
if (!inplace) {
572-
Py_DECREF(out);
573-
}
572+
Py_DECREF(out);
574573
PyErr_SetString(PyExc_NotImplementedError, "rapidjson.units.Units do not support this operation.");
575574
return NULL;
576575
}

0 commit comments

Comments
 (0)