|
1 | 1 | # Introduction to Fable.Python |
2 | 2 |
|
3 | | -*Generated on 2025-12-22 14:47 UTC using Fable v5.0.0-alpha.21* |
| 3 | +*Generated on 2025-12-25 08:26 UTC using Fable v5.0.0-alpha.21* |
4 | 4 |
|
5 | 5 | > This post is part of the [F# Advent Calendar |
6 | 6 | 2025](https://sergeytihon.com/2025/11/03/f-advent-calendar-in-english-2025/). Thank you, Sergey Tihon, for organizing |
@@ -838,16 +838,23 @@ class DecoratedUser: |
838 | 838 | Control how class members are generated for Python frameworks like Pydantic: |
839 | 839 |
|
840 | 840 | ```fsharp |
| 841 | +// BaseModel from Pydantic (import this from Fable.Python.Pydantic in |
| 842 | +// real code to get proper bindings) |
| 843 | +[<Import("BaseModel", "pydantic")>] |
| 844 | +type BaseModel() = class end |
| 845 | +
|
841 | 846 | [<Py.ClassAttributes(Py.ClassAttributeStyle.Attributes, false)>] |
842 | 847 | type PydanticModel() = |
| 848 | + inherit BaseModel() |
843 | 849 | member val Name: string = "" with get, set |
844 | 850 | member val Age: int = 0 with get, set |
845 | 851 | ``` |
846 | 852 |
|
847 | | -This generates class-level type annotations suitable for Pydantic: |
| 853 | +This generates class-level type annotations suitable for Pydantic. |
| 854 | +See the Pydantic chapter for more on working with Pydantic models: |
848 | 855 |
|
849 | 856 | ```python |
850 | | -class PydanticModel: |
| 857 | +class PydanticModel(BaseModel): |
851 | 858 | Age: int32 = int32.ZERO |
852 | 859 | Name: str = "" |
853 | 860 | ``` |
@@ -3423,13 +3430,7 @@ Utility functions for naming conversion and line classification: |
3423 | 3430 | ```fsharp |
3424 | 3431 | module Utils = |
3425 | 3432 | /// List of contributors to thank (Fable-style). |
3426 | | - let contributors = [| |
3427 | | - "@dbrattli" |
3428 | | - "@alfonsogarciacaro" |
3429 | | - "@ncave" |
3430 | | - "@MangelMaxime" |
3431 | | - "@claude 🤖" |
3432 | | - |] |
| 3433 | + let contributors = [| "@dbrattli"; "@alfonsogarciacaro"; "@ncave"; "@MangelMaxime"; "@claude 🤖" |] |
3433 | 3434 |
|
3434 | 3435 | /// Returns a random contributor from the list. |
3435 | 3436 | let randomContributor () : string = |
@@ -3539,7 +3540,8 @@ Parse lines into a document AST |
3539 | 3540 | lines |
3540 | 3541 | |> Seq.fold parseLine initial |
3541 | 3542 | |> flushState |
3542 | | - |> _.Blocks |> List.rev |
| 3543 | + |> _.Blocks |
| 3544 | + |> List.rev |
3543 | 3545 | ``` |
3544 | 3546 |
|
3545 | 3547 | ### Transform Module |
@@ -3720,7 +3722,8 @@ We've covered a lot of ground in this guide: |
3720 | 3722 | - **Testing**: Running F# code with pytest and other Python test runners |
3721 | 3723 | - **Fable v5**: The latest features including the Rust core and PyPI packages |
3722 | 3724 | - **Pydantic**: Building validated data models with Python's favorite library |
3723 | | -- **Units of Measure**: Compile-time dimensional analysis that vanishes at runtime |
| 3725 | +- **FastAPI**: Building type-safe web APIs in the Python ecosystem |
| 3726 | +- **Units of Measure**: Compile-time dimensional analysis that vanishes (erased) at runtime |
3724 | 3727 | - **Fable.Literate**: A self-documenting literate programming converter |
3725 | 3728 |
|
3726 | 3729 | ### The Punchline |
|
0 commit comments