Skip to content

Commit c9b0a87

Browse files
committed
fix: Python named arguments needs snake casing
1 parent b825a4f commit c9b0a87

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/Fable.Transforms/Python/Fable2Python.Transforms.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,9 @@ let transformCallArgs
682682
|> List.unzip
683683
|> fun (kv, stmts) ->
684684
kv
685-
|> List.map (fun (keyword, value) -> Keyword.keyword (Identifier keyword, value)),
685+
|> List.map (fun (keyword, value) ->
686+
Keyword.keyword (Identifier(Naming.toPythonNaming keyword), value)
687+
),
686688
stmts |> List.collect id
687689

688690
args, Some objArg, stmts
@@ -717,7 +719,9 @@ let transformCallArgs
717719
|> List.unzip
718720
|> fun (kv, stmts) ->
719721
kv
720-
|> List.map (fun (keyword, value) -> Keyword.keyword (Identifier keyword, value)),
722+
|> List.map (fun (keyword, value) ->
723+
Keyword.keyword (Identifier(Naming.toPythonNaming keyword), value)
724+
),
721725
stmts |> List.collect id
722726

723727
[], Some objArg, stmts

tests/Python/TestNonRegression.fs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,22 @@ type Disposable(cancel) =
265265
let ``test static properties works when inheriting from IDisposable`` () =
266266
let d: IDisposable = Disposable.Empty
267267
d.Dispose()
268+
269+
// Test that named arguments are converted to snake_case in Python
270+
module NamedArgsSnakeCase =
271+
[<AttachMembers>]
272+
type TestRunner(testCase: string, ?configArgs: string array) =
273+
member val TestCase = testCase with get
274+
member val ConfigArgs = defaultArg configArgs [||] with get
275+
276+
[<Fact>]
277+
let ``test named arguments are converted to snake_case`` () =
278+
// Test with optional named argument
279+
let runner1 = NamedArgsSnakeCase.TestRunner("test", configArgs = [| "arg1"; "arg2" |])
280+
equal "test" runner1.TestCase
281+
equal [| "arg1"; "arg2" |] runner1.ConfigArgs
282+
283+
// Test with all named arguments
284+
let runner2 = NamedArgsSnakeCase.TestRunner(testCase = "test2", configArgs = [| "arg3" |])
285+
equal "test2" runner2.TestCase
286+
equal [| "arg3" |] runner2.ConfigArgs

0 commit comments

Comments
 (0)