Nerodia Reference Manual

6. Type Conversions🔗

When using annotations like @[py_module_fn] or @[py_module_attr], Nerodia constructs a Python signature from the Lean definition's signature, translating the Lean types of arguments and results into Python types. In the simple case, a Nerodia type representing a Python type (e.g., PyBool) is translated directly to its corresponding Python type. Standard Lean types (e.g., Bool), on the other hand, require conversion, and Nerodia follows the mapping below in doing so.

Lean Type

Python Argument Type

Python Result Type

IO T

—

T

BaseIO T

—

T

Unit

—

None

Empty

—

Never

Option T

T | None

T | None

Bool

bool

bool

String

str

str

ByteArray

Buffer

bytes

Float

int | float

float

Float32

int | float

float

Int

int

int

Nat

int

int

Fin

int

int

IntX

int

int

UIntX

int

int

  • IntX, fixed-width integers: ISize, Int64, Int32, Int16, Int8

  • UIntX, fixed-width unsigned integers: USize, UInt64, UInt32, UInt16, UInt8