@@ -3223,7 +3223,7 @@ let getUnionFieldsAsIdents (_com: IPythonCompiler) _ctx (_ent: Fable.Entity) =
32233223let getEntityFieldsAsIdents ( com : IPythonCompiler ) ( ent : Fable.Entity ) =
32243224 let entityNamingConvention =
32253225 if shouldUseRecordFieldNaming ent then
3226- Naming.toRecordFieldSnakeCase
3226+ Naming.toFieldSnakeCase
32273227 else
32283228 Naming.toPythonNaming
32293229
@@ -3248,7 +3248,7 @@ let getEntityFieldsAsProps (com: IPythonCompiler) ctx (ent: Fable.Entity) =
32483248 else
32493249 let namingConvention =
32503250 if shouldUseRecordFieldNaming ent then
3251- Naming.toRecordFieldSnakeCase
3251+ Naming.toFieldSnakeCase
32523252 else
32533253 Naming.toPythonNaming
32543254
@@ -3290,7 +3290,7 @@ let declareDataClassType
32903290 consArgs.Args.[ i]. Arg
32913291 else
32923292 // Fallback to field name if consArgs doesn't have enough args
3293- com.GetIdentifier( ctx, field.Name |> Naming.toRecordFieldSnakeCase |> Helpers.clean)
3293+ com.GetIdentifier( ctx, field.Name |> Naming.toFieldSnakeCase |> Helpers.clean)
32943294
32953295 // Uncurry lambda types for field annotations since fields store uncurried functions
32963296 let fieldType =
@@ -3943,7 +3943,7 @@ let transformAttachedProperty
39433943 // Apply the same naming convention as record fields for record types
39443944 let propertyName =
39453945 //if shouldUseRecordFieldNaming ent then
3946- // memb.Name |> Naming.toRecordFieldSnakeCase |> Helpers.clean
3946+ // memb.Name |> Naming.toFieldSnakeCase |> Helpers.clean
39473947 //else
39483948 memb.Name |> Naming.toPropertyNaming
39493949
@@ -4097,9 +4097,10 @@ let transformUnion (com: IPythonCompiler) ctx (ent: Fable.Entity) (entName: stri
40974097 let fieldAnnotations =
40984098 uci.UnionCaseFields
40994099 |> List.map ( fun field ->
4100- // Convert to snake_case and clean to remove invalid characters like apostrophes
4101- // Handles: "Item" -> "item", "Item1" -> "item1", "MyField" -> "my_field"
4102- let fieldName = field.Name |> Naming.toSnakeCase |> Helpers.clean
4100+ // toFieldSnakeCase appends '_' to camelCase names ("name" -> "name_") so a
4101+ // field can't collide with the inherited `Union.name` property, which @dataclass
4102+ // would treat as a default value ("non-default argument follows default"). See #4645.
4103+ let fieldName = field.Name |> Naming.toFieldSnakeCase |> Helpers.clean
41034104 // Uncurry lambda types for field annotations since union case fields
41044105 // store uncurried functions at runtime (same as record fields)
41054106 let fieldType =
@@ -4238,7 +4239,7 @@ let transformClassWithCompilerGeneratedConstructor
42384239 |> List.collecti ( fun i field ->
42394240 let fieldName =
42404241 if shouldUseRecordFieldNaming ent then
4241- field.Name |> Naming.toRecordFieldSnakeCase |> Helpers.clean
4242+ field.Name |> Naming.toFieldSnakeCase |> Helpers.clean
42424243 else
42434244 match Util.getFieldNamingKind com field.FieldType field.Name with
42444245 | InstancePropertyBacking -> field.Name |> Naming.toPropertyBackingFieldNaming
@@ -4680,7 +4681,7 @@ let transformStaticProperty
46804681 // printfn "transformStaticProperty: %A" propName
46814682 let propertyName =
46824683 if shouldUseRecordFieldNaming ent then
4683- propName |> Naming.toRecordFieldSnakeCase |> Helpers.clean
4684+ propName |> Naming.toFieldSnakeCase |> Helpers.clean
46844685 else
46854686 propName |> Naming.toPropertyNaming
46864687
0 commit comments