Skip to content
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
  • Loading branch information
belm0 and serhiy-storchaka authored Feb 10, 2024
commit d37b5b81c582a8964fe83683e88660e9c4d4017b
1 change: 1 addition & 0 deletions Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,7 @@ def test_formatting(self):
('z>z6.1f', '-0.', 'zzz0.0'),
('x>z6.1f', '-0.', 'xxx0.0'),
('🖤>z6.1f', '-0.', '🖤🖤🖤0.0'), # multi-byte fill char
Comment thread
belm0 marked this conversation as resolved.
('\0>z6.1f', '-0.', '\0\0\00.0'), # null fill char
Comment thread
belm0 marked this conversation as resolved.
Outdated

# issue 114563 ('z' format on F type in cdecimal)
('z3,.10F', '-6.24E-323', '0.0000000000'),
Expand Down
13 changes: 3 additions & 10 deletions Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3377,14 +3377,7 @@ pydec_format(PyObject *dec, PyObject *fmt, decimal_state *state)
PyObject *u;

if (state->PyDecimal == NULL) {
PyObject *obj = PyImport_ImportModule("_pydecimal");
if (obj == NULL) {
return NULL;
}

state->PyDecimal = PyObject_GetAttrString(obj, "Decimal");
Py_DECREF(obj);

state->PyDecimal = _PyImport_GetModuleAttrString("_pydecimal", "Decimal");
if (state->PyDecimal == NULL) {
return NULL;
}
Expand All @@ -3395,13 +3388,13 @@ pydec_format(PyObject *dec, PyObject *fmt, decimal_state *state)
return NULL;
}

pydec = PyObject_CallFunctionObjArgs(state->PyDecimal, u, NULL);
pydec = PyObject_CallOneArg(state->PyDecimal, u);
Comment thread
belm0 marked this conversation as resolved.
Py_DECREF(u);
if (pydec == NULL) {
return NULL;
}

result = PyObject_CallMethod(pydec, "__format__", "(O)", fmt);
result = PyObject_Format(pydec, fmt);
Py_DECREF(pydec);

if (result == NULL) {
Comment thread
belm0 marked this conversation as resolved.
Outdated
Expand Down