Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* [Python] Fix `ResizeArray` compatibility with `Seq`/`Array` (by @dbrattli)
* [Python] Fix `ResizeArray` compatibility with `Seq`/`Array` functions (by @dbrattli)
* [Python] Fix `FSharpList` generic type parameter handling for `IEnumerable_1` compatibility (by @dbrattli)

## 5.0.0-alpha.20 - 2025-12-08

Expand Down
3 changes: 2 additions & 1 deletion src/Fable.Compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* [Python] Fix `ResizeArray` compatibility with `Seq`/`Array` (by @dbrattli)
* [Python] Fix `ResizeArray` compatibility with `Seq`/`Array` functions (by @dbrattli)
* [Python] Fix `FSharpList` generic type parameter handling for `IEnumerable_1` compatibility (by @dbrattli)

## 5.0.0-alpha.19 - 2025-12-08

Expand Down
12 changes: 12 additions & 0 deletions src/Fable.Transforms/Python/Fable2Python.Transforms.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2775,6 +2775,9 @@ let calculateTypeParams (com: IPythonCompiler) ctx (info: Fable.MemberFunctionOr
|> Set.union explicitGenerics
|> Set.union signatureGenerics
|> Set.union bodyGenerics
// Filter out generics that are already defined at class level
|> Set.difference
<| ctx.ScopedTypeParams

makeFunctionTypeParams com ctx repeatedGenerics

Expand Down Expand Up @@ -3696,6 +3699,15 @@ let rec transformDeclaration (com: IPythonCompiler) ctx (decl: Fable.Declaration
if classAttributes.Style = ClassStyle.Properties && not classAttributes.Init then
failwithf "ClassAttributes.Init must be true when ClassAttributes.Style is ClassStyle.Properties"

// Add class generic parameters to scoped type params so methods don't redeclare them
let classGenericParams =
ent.GenericParameters
|> List.map (fun p -> p.Name |> Helpers.clean)
|> Set.ofList

let ctx =
{ ctx with ScopedTypeParams = Set.union ctx.ScopedTypeParams classGenericParams }

let classMembers =
decl.AttachedMembers
|> List.collect (fun memb ->
Expand Down
14 changes: 14 additions & 0 deletions src/Fable.Transforms/Python/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ let (|TypedArrayCompatible|_|) (com: Compiler) (arrayKind: ArrayKind) t =
let error com msg =
Helper.ConstructorCall(makeIdentExpr "Exception", Any, [ msg ])

/// Wraps ResizeArray (Python list) arguments with to_enumerable for Seq module compatibility.
let wrapResizeArrayToEnumerable com (arg: Expr) =
let rec getInnerType expr =
match expr with
| TypeCast(inner, _) -> getInnerType inner
| _ -> expr.Type

match getInnerType arg with
| Array(_, ResizeArray) -> Helper.LibCall(com, "util", "to_enumerable", arg.Type, [ arg ])
| _ -> arg

let coreModFor =
function
| BclGuid -> "guid"
Expand Down Expand Up @@ -1548,6 +1559,9 @@ let formattableString
let seqModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: Expr option) (args: Expr list) =
// printfn "seqModule: %A" i.CompiledName

// Wrap ResizeArray arguments with to_enumerable for type compatibility
let args = args |> List.map (wrapResizeArrayToEnumerable com)

match i.CompiledName, args with
| "Cast", [ arg ] -> Some arg // Erase
| "CreateEvent", [ addHandler; removeHandler; createHandler ] ->
Expand Down
Loading