8000 gh-114563: C decimal falls back to pydecimal for unsupported format strings by belm0 · Pull Request #114879 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-114563: C decimal falls back to pydecimal for unsupported format strings #114879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 12, 2024
Prev Previous commit
Next Next commit
pass context directly to __format__()
  • Loading branch information
belm0 committed Feb 11, 2024
commit ab4f2d7fea366507294a143fefb45c656ff81780
6 changes: 0 additions & 6 deletions Lib/_pydecimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3841,12 +3841,6 @@ def __format__(self, specifier, context=None, _localeconv=None):
# of the formatting to the _format_number function
return _format_number(adjusted_sign, intpart, fracpart, exp, spec)

def _fallback_format(self, specifier, rounding, caps):
"""returns `__format__(specifier)` using a temporary context"""
c = Context(rounding=rounding, capitals=caps)
return self.__format__(specifier, c)


def _dec_from_triple(sign, coefficient, exponent, special=False):
"""Create a decimal instance directly, without any validation,
normalization (e.g. removal of leading zeros) or argument
Expand Down
8 changes: 1 addition & 7 deletions Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3374,8 +3374,6 @@ pydec_format(PyObject *dec, PyObject *context, PyObject *fmt, decimal_state *sta
{
PyObject *result;
PyObject *pydec;
PyObject *rounding;
PyObject *caps;
PyObject *u;

if (state->PyDecimal == NULL) {
Expand All @@ -3396,11 +3394,7 @@ pydec_format(PyObject *dec, PyObject *context, PyObject *fmt, decimal_state *sta
return NULL;
}

rounding = context_getround(context, NULL);
caps = context_getcapitals(context, NULL);
result = PyObject_CallMethod(pydec, "_fallback_format", "(OOO)", fmt, rounding, caps);
Py_DECREF(rounding);
Py_DECREF(caps);
result = PyObject_CallMethod(pydec, "__format__", "(OO)", fmt, context);
Py_DECREF(pydec);

if (result == NULL && PyErr_ExceptionMatches(PyExc_ValueError)) {
Expand Down
0