Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit10c9db6

Browse files
authored
Merge pull requestRustPython#4392 from yt2b/fix_prefix_format
Prefix format with padding doesn't work correctly.
2 parentsf2bab80 +c8c5abe commit10c9db6

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

‎extra_tests/snippets/builtin_format.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,13 @@ def test_zero_padding():
3333
assertf"{0x1f5a5:c}"=="🖥"
3434
assert_raises(ValueError,"{:+c}".format,1,_msg="Sign not allowed with integer format specifier 'c'")
3535
assert_raises(ValueError,"{:#c}".format,1,_msg="Alternate form (#) not allowed with integer format specifier 'c'")
36+
assertf"{256:#010x}"=="0x00000100"
37+
assertf"{256:0=#10x}"=="0x00000100"
38+
assertf"{256:0>#10x}"=="000000x100"
39+
assertf"{256:0^#10x}"=="000x100000"
40+
assertf"{256:0<#10x}"=="0x10000000"
41+
assertf"{512:+#010x}"=="+0x0000200"
42+
assertf"{512:0=+#10x}"=="+0x0000200"
43+
assertf"{512:0>+#10x}"=="0000+0x200"
44+
assertf"{512:0^+#10x}"=="00+0x20000"
45+
assertf"{512:0<+#10x}"=="+0x2000000"

‎vm/src/format.rs‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,7 @@ impl FormatSpec {
504504
},
505505
None =>self.format_int_radix(magnitude,10),
506506
};
507-
let magnitude_string =format!(
508-
"{}{}",
509-
prefix,
510-
self.add_magnitude_separators(raw_magnitude_string_result?)
511-
);
512-
507+
let magnitude_string =self.add_magnitude_separators(raw_magnitude_string_result?);
513508
let format_sign =self.sign.unwrap_or(FormatSign::Minus);
514509
let sign_str =match num.sign(){
515510
Sign::Minus =>"-",
@@ -519,8 +514,8 @@ impl FormatSpec {
519514
FormatSign::MinusOrSpace =>" ",
520515
},
521516
};
522-
523-
self.format_sign_and_align(&magnitude_string,sign_str,FormatAlign::Right)
517+
let sign_prefix =format!("{}{}", sign_str, prefix);
518+
self.format_sign_and_align(&magnitude_string,&sign_prefix,FormatAlign::Right)
524519
}
525520

526521
pub(crate)fnformat_string(&self,s:&str) ->Result<String,&'staticstr>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp