Skip to content

Commit 5fcf708

Browse files
authored
[Python] Fix regression for %A format specifier to output booleans as lowercase (#4289)
* fix(python): Fix `%A` format specifier to output booleans as lowercase * doc: Fix changelog entries
1 parent 92bf397 commit 5fcf708

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

src/Fable.Cli/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Fixed
11+
12+
* [Python] Fix regression `%A` format specifier to output booleans as lowercase `true`/`false` (by @dbrattli)
13+
1014
## 5.0.0-alpha.19 - 2025-12-04
1115

1216
### Fixed
@@ -15,8 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1519

1620
### Added
1721

18-
* [Python] Add support for `[<Py.Decorate>]` attribute on methods (previously only worked on classes)
19-
* [Python] Add new `[<Py.ClassMethod>]` attribute to emit @classmethod instead of @staticmethod
22+
* [Python] Add support for `[<Py.Decorate>]` attribute on methods (previously only worked on classes) (by @dbrattli)
23+
* [Python] Add new `[<Py.ClassMethod>]` attribute to emit @classmethod instead of @staticmethod (by @dbrattli)
2024
* [Python] Added support for Pydantic serialization of core numeric and array types (by @dbrattli)
2125

2226
## 5.0.0-alpha.18 - 2025-12-03

src/Fable.Compiler/CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
### Fixed
11+
12+
* [Python] Fix regression `%A` format specifier to output booleans as lowercase `true`/`false` (by @dbrattli)
13+
1014
## 5.0.0-alpha.18 - 2025-12-04
1115

1216
### Fixed
@@ -15,8 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1519

1620
### Added
1721

18-
* [Python] Add support for `[<Py.Decorate>]` attribute on methods (previously only worked on classes)
19-
* [Python] Add new `[<Py.ClassMethod>]` attribute to emit @classmethod instead of @staticmethod
22+
* [Python] Add support for `[<Py.Decorate>]` attribute on methods (previously only worked on classes) (by @dbrattli)
23+
* [Python] Add new `[<Py.ClassMethod>]` attribute to emit @classmethod instead of @staticmethod (by @dbrattli)
2024
* [Python] Added support for Pydantic serialization of core numeric and array types (by @dbrattli)
2125

2226
## 5.0.0-alpha.17 - 2025-12-03

src/Fable.Core/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Added
1313

14-
* [Python] Add support for [<Py.Decorate>] attribute on methods (previously only worked on classes)
15-
* [Python] Add new [<Py.ClassMethod>] attribute to emit @classmethod instead of @staticmethod
14+
* [Python] Add support for [<Py.Decorate>] attribute on methods (previously only worked on classes) (by @dbrattli)
15+
* [Python] Add new [<Py.ClassMethod>] attribute to emit @classmethod instead of @staticmethod (by @dbrattli)
1616

1717
## 5.0.0-beta.2 - 2025-11-19
1818

src/fable-library-py/src/strings.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ mod printf {
160160
"Int64" => format!("{}:i64", arg.str()?),
161161
"UInt32" => format!("{}:u32", arg.str()?),
162162
"UInt64" => format!("{}:u64", arg.str()?),
163+
// Handle booleans with F# lowercase representation (true/false)
164+
"bool" => {
165+
if arg.is_truthy()? {
166+
TRUE_STR.to_string()
167+
} else {
168+
FALSE_STR.to_string()
169+
}
170+
}
163171
_ => arg.str()?.to_string(),
164172
}
165173
};

tests/Python/TestString.fs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,19 @@ let ``test Extended string interpolation syntax`` () =
127127
let cssNew = $$""".{{classAttr}}:hover {background-color: #eee;}"""
128128
cssNew |> equal ".item-panel:hover {background-color: #eee;}"
129129

130+
[<Fact>]
131+
let ``test sprintf \"%A\" formats booleans as lowercase`` () =
132+
// Test that %A formats booleans as lowercase true/false (F# semantics)
133+
let result = sprintf "%A" true
134+
equal "true" result
135+
136+
let result2 = sprintf "%A" false
137+
equal "false" result2
138+
139+
// Also test in composed context
140+
let optResult = sprintf "Some(%A)" true
141+
equal "Some(true)" optResult
142+
130143
[<Fact>]
131144
let ``test sprintf \"%A\" with lists works`` () =
132145
let xs = ["Hi"; "Hello"; "Hola"]

0 commit comments

Comments
 (0)