Skip to content

Commit

Permalink
[Python] Do not translate .toString methods to str (#3622)
Browse files Browse the repository at this point in the history
* Move code to replacements

* Update changelog
  • Loading branch information
dbrattli authored Nov 28, 2023
1 parent cd5d962 commit 7a335bb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fix #3617: Fix comparaison between list option when one is None
* Fix #3615: Fix remove from dictionary with tuple as key
* Fix #3598: Using obj () now generated an empty dict instead of None
* Fix #3597: Do not translate .toString methods to str

## 4.6.0 - 2023-11-27

Expand Down
27 changes: 0 additions & 27 deletions src/Fable.Transforms/Python/Fable2Python.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3959,14 +3959,6 @@ module Util =
_,
_range) -> transformAsArray com ctx expr info

| Fable.Call(Fable.Get(expr, Fable.FieldGet { Name = name }, _, _),
_info,
_,
_range) when name.ToLower() = "tostring" ->
let func = Expression.name "str"
let left, stmts = com.TransformAsExpr(ctx, expr)
Expression.call (func, [ left ]), stmts

| Fable.Call(Fable.Get(expr, Fable.FieldGet { Name = "Equals" }, _, _),
{ Args = [ arg ] },
_,
Expand All @@ -3975,25 +3967,6 @@ module Util =
let left, stmts' = com.TransformAsExpr(ctx, expr)
Expression.compare (left, [ Eq ], [ right ]), stmts @ stmts'

| Fable.Call(Fable.Get(expr, Fable.FieldGet { Name = "split" }, _, _),
{ Args = [ Fable.Value(kind = Fable.StringConstant "") ] },
_,
_range) ->
let func = Expression.name "list"
let value, stmts = com.TransformAsExpr(ctx, expr)
Expression.call (func, [ value ]), stmts

| Fable.Call(Fable.Get(expr,
Fable.FieldGet { Name = "charCodeAt" },
_,
_),
_info,
_,
_range) ->
let func = Expression.name "ord"
let value, stmts = com.TransformAsExpr(ctx, expr)
Expression.call (func, [ value ]), stmts

| Fable.Call(callee, info, _, range) ->
transformCall com ctx range callee info

Expand Down
4 changes: 3 additions & 1 deletion src/Fable.Transforms/Python/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,9 @@ let toList com returnType expr =
Helper.LibCall(com, "list", "ofSeq", returnType, [ expr ])

let stringToCharArray t e =
Helper.InstanceCall(e, "split", t, [ makeStrConst "" ])
//Helper.InstanceCall(e, "split", t, [ makeStrConst "" ])
// Write as global call `list` instead
Helper.GlobalCall("list", t, [ e ])

let toSeq t (e: Expr) =
match e.Type with
Expand Down

0 comments on commit 7a335bb

Please sign in to comment.