Example: Using exclude options.
()
| 123 | |
| 124 | |
| 125 | def example_exclude_options(): |
| 126 | """Example: Using exclude options.""" |
| 127 | print("=== Exclude Options ===") |
| 128 | |
| 129 | user = User( |
| 130 | id=3, |
| 131 | name='Charlie Brown', |
| 132 | email='charlie@example.com' |
| 133 | # age, active, and address use defaults or are None |
| 134 | ) |
| 135 | |
| 136 | print("All fields (default):") |
| 137 | toon_all = encode_pydantic(user, exclude_unset=False) |
| 138 | print(toon_all) |
| 139 | print() |
| 140 | |
| 141 | print("Exclude unset fields:") |
| 142 | toon_unset = encode_pydantic(user, exclude_unset=True) |
| 143 | print(toon_unset) |
| 144 | print() |
| 145 | |
| 146 | print("Exclude None values:") |
| 147 | toon_none = encode_pydantic(user, exclude_none=True) |
| 148 | print(toon_none) |
| 149 | print() |
| 150 | |
| 151 | |
| 152 | def example_field_aliases(): |
no test coverage detected
searching dependent graphs…