From 8e8523413436cdb92ccfc459d2dd69e07bd8d29a Mon Sep 17 00:00:00 2001 From: yt2b Date: Mon, 2 Jan 2023 21:14:32 +0900 Subject: [PATCH 1/2] Fix format_int --- common/src/format.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/common/src/format.rs b/common/src/format.rs index c8849895d..f9cf05e95 100644 --- a/common/src/format.rs +++ b/common/src/format.rs @@ -513,13 +513,9 @@ impl FormatSpec { Some(_) | None => Err("%c arg not in range(0x110000)"), }, }, - Some(FormatType::GeneralFormatUpper) => { - Err("Unknown format code 'G' for object of type 'int'") - } - Some(FormatType::GeneralFormatLower) => { - Err("Unknown format code 'g' for object of type 'int'") - } - Some(FormatType::FixedPointUpper) + Some(FormatType::GeneralFormatUpper) + | Some(FormatType::GeneralFormatLower) + | Some(FormatType::FixedPointUpper) | Some(FormatType::FixedPointLower) | Some(FormatType::ExponentUpper) | Some(FormatType::ExponentLower) From bd35b00184b9b19be394928b8affb0ae80a76005 Mon Sep 17 00:00:00 2001 From: yt2b Date: Mon, 2 Jan 2023 21:14:46 +0900 Subject: [PATCH 2/2] Add test --- extra_tests/snippets/builtin_format.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extra_tests/snippets/builtin_format.py b/extra_tests/snippets/builtin_format.py index 838c917a5..fcf395051 100644 --- a/extra_tests/snippets/builtin_format.py +++ b/extra_tests/snippets/builtin_format.py @@ -64,3 +64,5 @@ assert f"{123.456:09,}" == "0,123.456" assert f"{123.456:010,}" == "00,123.456" assert f"{123.456:011,}" == "000,123.456" assert f"{123.456:+011,}" == "+00,123.456" +assert f"{1234:.3g}" == "1.23e+03" +assert f"{1234567:.6G}" == "1.23457E+06"