There is dedicated code for formatting integer literals in f-strings, which avoids converting C integers to Python integer objects just for formatting them as strings. It is used by the FormattedValueNode in ExprNodes.py.
The same should be done for C float/double values, as Python provides PyOS_double_to_string(). See CPython's own float formatting in unicodeobject.c and formatter_unicode.c.
- implement relevant tests in
tests/run/fstring.pyx and/or check if tests/run/test_fstring.pyx (copied from CPython's test suite) covers this sufficiently
- extract the relevant parts of CPython's formatting implementation (potentially limiting it to easy to support formats)
- create a new C utility function in
TypeConversion.c that formats double values
- implement
CFloatType.can_coerce_to_pystring() in PyrexTypes.py to make it return True when supported
- implement
CFloatType.convert_to_pystring() to call the formatting C function.
This can be done incrementally for selected formatting modifiers, e.g. a format like f"{x: .2f}" should be fairly easy to support and covers a large part of the usages.
Hint: this ticket requires good C skills.
There is dedicated code for formatting integer literals in f-strings, which avoids converting C integers to Python integer objects just for formatting them as strings. It is used by the
FormattedValueNodeinExprNodes.py.The same should be done for C float/double values, as Python provides PyOS_double_to_string(). See CPython's own float formatting in unicodeobject.c and formatter_unicode.c.
tests/run/fstring.pyxand/or check iftests/run/test_fstring.pyx(copied from CPython's test suite) covers this sufficientlyTypeConversion.cthat formats double valuesCFloatType.can_coerce_to_pystring()inPyrexTypes.pyto make it returnTruewhen supportedCFloatType.convert_to_pystring()to call the formatting C function.This can be done incrementally for selected formatting modifiers, e.g. a format like
f"{x: .2f}"should be fairly easy to support and covers a large part of the usages.Hint: this ticket requires good C skills.