Skip to content
Open
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
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"rollForward": false
},
"fable": {
"version": "5.13.0",
"version": "5.15.0",
"commands": [
"fable"
],
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ requires-python = ">= 3.12, < 4"
readme = "README.md"
license = "MIT"
dependencies = [
"fable-library==5.13.0",
"fable-library==5.15.0",
"pyright>=1.1.411",
]

Expand Down
11 changes: 8 additions & 3 deletions src/fable/Types.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Utilities for detecting and working with Fable types at runtime in Python.
/// These helpers are useful when you need to distinguish between native Python types
/// and Fable-compiled F# types (e.g., Int32, Float64, FSharpArray).
/// and Fable-compiled F# types (e.g., int, float, Int64, FSharpArray).
module Fable.Python.Fable.Types

open Fable.Core
Expand All @@ -9,9 +9,11 @@ open Fable.Core
[<Emit("type($0).__name__")>]
let typeName (o: obj) : string = nativeOnly

/// Check if an object is a Fable integral type (Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64)
/// Check if an object is an F# integral type.
/// The default F# int compiles to Python's native int; other widths use Fable runtime types.
let isIntegralType (o: obj) : bool =
match typeName o with
| "int"
| "Int8"
| "Int16"
| "Int32"
Expand All @@ -22,9 +24,12 @@ let isIntegralType (o: obj) : bool =
| "UInt64" -> true
| _ -> false

/// Check if an object is a Fable numeric type (integral types + Float32, Float64)
/// Check if an object is an F# numeric type.
/// The default F# int and float compile to Python's native int and float.
let isNumericType (o: obj) : bool =
match typeName o with
| "int"
| "float"
| "Int8"
| "Int16"
| "Int32"
Expand Down
8 changes: 4 additions & 4 deletions test/TestTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ open Fable.Python.Fable.Types
// Test typeName function

[<Fact>]
let ``test typeName returns Int32 for int`` () =
let ``test typeName returns int for int`` () =
let value = 42
typeName value |> equal "Int32"
typeName value |> equal "int"

[<Fact>]
let ``test typeName returns Int64 for int64`` () =
let value = 42L
typeName value |> equal "Int64"

[<Fact>]
let ``test typeName returns Float64 for float`` () =
let ``test typeName returns float for float`` () =
let value = 3.14
typeName value |> equal "Float64"
typeName value |> equal "float"

[<Fact>]
let ``test typeName returns str for string`` () =
Expand Down
Loading
Loading