Skip to content

Commit d3dba62

Browse files
dbrattliclaude
andcommitted
Add ClassAttributes options table and Py.DataClass shorthand to docs
Explain the different style and init parameters for Py.ClassAttributes, and document Py.DataClass as a shorthand for frameworks like Pydantic. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2adef37 commit d3dba62

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

docs/docs/python/features.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,25 @@ class Config:
485485

486486
Without `ClassAttributes`, members would be generated as properties with instance backing.
487487

488+
| Parameter | Effect |
489+
| -------------------- | ---------------------------------------------------------- |
490+
| `style = Attributes` | Generate class-level type annotations |
491+
| `style = Properties` | Generate properties with instance attribute backing |
492+
| `init = false` | Don't generate `__init__` (Pydantic/dataclass provides it) |
493+
| `init = true` | Generate `__init__` with attribute assignments |
494+
495+
`Py.DataClass` is shorthand for `Py.ClassAttributes(style = Attributes, init = false)`.
496+
This is useful when working with frameworks like Pydantic, dataclasses, and attrs that
497+
expect class-level type annotations:
498+
499+
```fs
500+
[<Py.DataClass>]
501+
type User() =
502+
inherit BaseModel()
503+
member val Name: string = "" with get, set
504+
member val Age: int = 0 with get, set
505+
```
506+
488507
## Python Decorators
489508

490509
<p class="tag is-info is-medium">

0 commit comments

Comments
 (0)