website/docs/pydantic-lax-conversions.mdx
{/*
This page provides a complete reference for how Pyrefly converts types when working with Pydantic models in lax mode (the default). For background on how lax mode works, see the main Pydantic documentation.
Note: Types without a specific conversion rule (e.g., Callable, Any, custom classes) are converted to Any.
Named unions are used for atomic types to keep type signatures concise.
| Input Type | Named Union | Expanded Type |
|---|---|---|
int | LaxInt | int | bool | float | str | bytes | Decimal |
float | LaxFloat | int | bool | float | str | bytes | Decimal |
bool | LaxBool | bool | int | float | str | Decimal |
Decimal | LaxDecimal | Decimal | int | float | str |
str | LaxStr | str | bytes | bytearray |
bytes | LaxBytes | str | bytes | bytearray |
date | LaxDate | date | datetime | int | float | str | bytes | Decimal |
datetime | LaxDatetime | date | datetime | int | float | str | bytes | Decimal |
time | LaxTime | time | int | float | str | bytes | Decimal |
timedelta | LaxTimedelta | timedelta | int | float | str | bytes | Decimal |
Path | LaxPath | Path | str |
UUID | LaxUuid | UUID | str |
None | (no conversion) | None |
Notation:
T_converted means the type T is recursively converted using lax mode rules (e.g., int → LaxInt)T_flattened means the type T is converted and expanded (e.g., int → int | bool | float | str | bytes | Decimal)| Input Type/Container | Output Type/Container |
|---|---|
type[T] | type[T_converted] |
T1 | T2 | ... | T1_flattened | T2_flattened | ... |
list[T], set[T], frozenset[T], | |
Sequence[T], Iterable[T], deque[T], | |
tuple[T, ...] | Iterable[T_converted] |
tuple[T1, T2, ...] | Iterable[T1_flattened | T2_flattened | ...] |
dict[K, V] | Mapping[K, V_converted] |
Examples:
type[int] → type[LaxInt]int | bool → int | bool | float | str | bytes | Decimallist[int] → Iterable[LaxInt]tuple[int, str] → Iterable[int | bool | float | str | bytes | bytearray | Decimal]dict[str, int] → Mapping[str, LaxInt]