Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] PyO3 walking skeleton for Python #3804

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions src/Fable.Transforms/Python/Fable2Python.fs
Original file line number Diff line number Diff line change
Expand Up @@ -438,14 +438,14 @@ module Reflection =
| Fable.String -> pyTypeof "<class 'str'>" expr
| Fable.Number(kind, _b) ->
match kind, typ with
| _, Fable.Type.Number(UInt8, _) -> pyTypeof "<fable_modules.fable_library.types.uint8'>>" expr
| _, Fable.Type.Number(Int8, _) -> pyTypeof "<class 'fable_modules.fable_library.types.int8'>" expr
| _, Fable.Type.Number(Int16, _) -> pyTypeof "<class 'fable_modules.fable_library.types.int16'>" expr
| _, Fable.Type.Number(UInt16, _) -> pyTypeof "<class 'fable_modules.fable_library.types.uint16'>" expr
| _, Fable.Type.Number(UInt8, _) -> pyTypeof "<class fable.UInt8'>>" expr
| _, Fable.Type.Number(Int8, _) -> pyTypeof "<class 'fableInt8'>" expr
| _, Fable.Type.Number(Int16, _) -> pyTypeof "<class 'fable.Int16'>" expr
| _, Fable.Type.Number(UInt16, _) -> pyTypeof "<class 'fable.UInt16'>" expr
| _, Fable.Type.Number(Int32, _) -> pyTypeof "<class 'int'>" expr
| _, Fable.Type.Number(UInt32, _) -> pyTypeof "<class 'fable_modules.fable_library.types.uint32>" expr
| _, Fable.Type.Number(Int64, _) -> pyTypeof "<class 'fable_modules.fable_library.types.int64'>" expr
| _, Fable.Type.Number(UInt64, _) -> pyTypeof "<class 'fable_modules.fable_library.types.uint32'>" expr
| _, Fable.Type.Number(UInt32, _) -> pyTypeof "<class 'fable.UInt32>" expr
| _, Fable.Type.Number(Int64, _) -> pyTypeof "<class 'fable.Int64'>" expr
| _, Fable.Type.Number(UInt64, _) -> pyTypeof "<class 'fable.UInt36'>" expr
dbrattli marked this conversation as resolved.
Show resolved Hide resolved
| _, Fable.Type.Number(Float32, _) -> pyTypeof "<class 'fable_modules.fable_library.types.float32'>" expr
| _, Fable.Type.Number(Float64, _) -> pyTypeof "<class 'float'>" expr
| _ -> pyTypeof "<class 'int'>" expr
Expand Down
11 changes: 8 additions & 3 deletions src/fable-library-py/fable_library/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from typing import TypeAlias

# from ._core import Int64 as int64
from ._core import (
Int8,
Int16,
Int32,
Int64,
UInt8,
UInt16,
UInt32,
UInt64,
)


# from ._core import UInt64 as uint64

# Type aliases for the built-in types
byte: TypeAlias = UInt8
sbyte: TypeAlias = Int8
Expand All @@ -22,6 +21,8 @@
uint16: TypeAlias = UInt16
int32: TypeAlias = Int32
uint32: TypeAlias = UInt32
int64: TypeAlias = Int64
uint64: TypeAlias = UInt64

__all__ = [
"sbyte",
Expand All @@ -38,4 +39,8 @@
"UInt16",
"Int32",
"UInt32",
"Int64",
"UInt64",
"int64",
"uint64",
]
7 changes: 7 additions & 0 deletions src/fable-library-py/fable_library/core/_core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Numeric:
def __radd__(self, other: Any) -> Any: ...
def __rsub__(self, other: Any) -> Any: ...
def __rmul__(self, other: Any) -> Any: ...
def __abs__(self) -> Self: ...

@final
class UInt8(Numeric): ...
Expand All @@ -48,3 +49,9 @@ class UInt32(Numeric): ...

@final
class Int32(Numeric): ...

@final
class UInt64(Numeric): ...

@final
class Int64(Numeric): ...
12 changes: 2 additions & 10 deletions src/fable-library-py/fable_library/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
cast,
)

from .core import byte, int16, int32, sbyte, uint16, uint32
from .core import byte, int16, int32, int64, sbyte, uint16, uint32, uint64
from .util import Array, IComparable, compare


Expand Down Expand Up @@ -274,7 +274,7 @@ def __lt__(self, other: Any) -> bool:
else:
return True

return super().__lt__(other)
return False

def __hash__(self) -> int:
return hash(self.Data0)
Expand All @@ -293,14 +293,6 @@ class char(int):
__slots__ = ()


class int64(int):
__slots__ = ()


class uint64(int):
__slots__ = ()


class float32(float):
__slots__ = ()

Expand Down
4 changes: 2 additions & 2 deletions src/fable-library-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn _core(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<UInt16>()?;
m.add_class::<Int32>()?;
m.add_class::<UInt32>()?;
//m.add_class::<Int64>()?;
//m.add_class::<UInt64>()?;
m.add_class::<Int64>()?;
m.add_class::<UInt64>()?;
Ok(())
}
Loading
Loading