Python Code Generation
paradox generate --python [--path PATH]
Product Types
Input:
type Person
name: Text
age: Integer
admin: Boolean
Output:
from __future__ import annotations
from dataclasses import dataclass
from typing import NewType, Callable, Literal
@dataclass
class Person:
name: str
age: int
admin: bool
Products become @dataclass classes.
Validators
def valid_person(x: Person) -> tuple[Person, None] | tuple[None, str]:
errors: list[str] = []
if errors:
return (None, "; ".join(errors))
return (x, None)
def is_valid_person(x: Person) -> bool:
result, _ = valid_person(x)
return result is not None
Validators return a result tuple: (value, None) on success, (None, error_message) on failure.
Type Mapping
| Paradox | Python |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|