Relax requirements on precision format, allow 0-prefixes

Closes #915
This commit is contained in:
Sergey B Kirpichev
2025-02-28 03:39:00 +03:00
parent 4c9a2ef9cd
commit 849e185ede
2 changed files with 4 additions and 2 deletions
+1 -1
View File
@@ -1400,7 +1400,7 @@ _FLOAT_FORMAT_SPECIFICATION_MATCHER = re.compile(r"""
(?P<zeropad>0)?
(?P<width>0|[1-9][0-9]*)?
(?P<thousands_separators>[,_])?
(?:\.(?P<precision>0|[1-9][0-9]*))?
(?:\.(?P<precision>[0-9]+))?
(?P<rounding>[UDYZN])?
(?P<type>[aAbeEfFgG%])?
""", re.DOTALL | re.VERBOSE).fullmatch
+3 -1
View File
@@ -62,7 +62,8 @@ def fmt_str(draw, types='fFeE', for_complex=False):
res += gchar
# Precision
prec = draw(st.sampled_from(['']*7 + list(map(str, range(40)))))
prec = draw(st.sampled_from(['']*7 + list(map(str, range(40)))
+ ['0' + str(_) for _ in range(40)]))
if prec:
res += '.' + prec
@@ -468,6 +469,7 @@ def test_mpf_fmt_cpython():
allow_infinity=True,
allow_subnormal=True))
@example(fmt='.0g', x=9.995074823339339e-05) # issue 880
@example(fmt='.016f', x=0.1) # issue 915
def test_mpf_floats_bulk(fmt, x):
'''
These are additional random tests that check that mp.mpf and fp.mpf yield