Skip to content

Commit dfc532b

Browse files
committed
using higher level base model
1 parent 10e8173 commit dfc532b

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

src/python-fastui/fastui/components/__init__.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class Heading(BaseModel, extra='forbid'):
138138
level: _t.Literal[1, 2, 3, 4, 5, 6] = 1
139139
"""The level of the heading. 1 is the largest, 6 is the smallest."""
140140

141-
html_id: _t.Union[str, None] = _p.Field(default=None)
141+
html_id: _t.Union[str, None] = None
142142
"""Optional HTML ID to apply to the heading's HTML component."""
143143

144144
class_name: _class_name.ClassNameField = None
@@ -224,10 +224,10 @@ class Button(BaseModel, extra='forbid'):
224224
text: str
225225
"""The text to display on the button."""
226226

227-
on_click: _t.Union[events.AnyEvent, None] = _p.Field(default=None)
227+
on_click: _t.Union[events.AnyEvent, None] = None
228228
"""Optional event to trigger when the button is clicked."""
229229

230-
html_type: _t.Union[_t.Literal['button', 'reset', 'submit'], None] = _p.Field(default=None)
230+
html_type: _t.Union[_t.Literal['button', 'reset', 'submit'], None] = None
231231
"""Optional HTML type of the button. If None, defaults to 'button'."""
232232

233233
named_style: _class_name.NamedStyleField = None
@@ -246,7 +246,7 @@ class Link(BaseModel, extra='forbid'):
246246
components: '_t.List[AnyComponent]'
247247
"""List of components to render attached to the link."""
248248

249-
on_click: _t.Union[events.AnyEvent, None] = _p.Field(default=None)
249+
on_click: _t.Union[events.AnyEvent, None] = None
250250
"""Optional event to trigger when the link is clicked."""
251251

252252
mode: _t.Union[_t.Literal['navbar', 'footer', 'tabs', 'vertical', 'pagination'], None] = None
@@ -287,13 +287,13 @@ class Navbar(BaseModel, extra='forbid'):
287287
title: _t.Union[str, None] = None
288288
"""Optional title to display in the navbar."""
289289

290-
title_event: _t.Union[events.AnyEvent, None] = _p.Field(default=None)
290+
title_event: _t.Union[events.AnyEvent, None] = None
291291
"""Optional event to trigger when the title is clicked. Often used to navigate to the home page."""
292292

293-
start_links: _t.List[Link] = _p.Field(default=[])
293+
start_links: _t.List[Link] = []
294294
"""List of links to render at the start of the navbar."""
295295

296-
end_links: _t.List[Link] = _p.Field(default=[])
296+
end_links: _t.List[Link] = []
297297
"""List of links to render at the end of the navbar."""
298298

299299
class_name: _class_name.ClassNameField = None
@@ -318,7 +318,7 @@ class Footer(BaseModel, extra='forbid'):
318318
links: _t.List[Link]
319319
"""List of links to render in the footer."""
320320

321-
extra_text: _t.Union[str, None] = _p.Field(default=None)
321+
extra_text: _t.Union[str, None] = None
322322
"""Optional extra text to display in the footer."""
323323

324324
class_name: _class_name.ClassNameField = None
@@ -340,10 +340,10 @@ class Modal(BaseModel, extra='forbid'):
340340
footer: '_t.Union[_t.List[AnyComponent], None]' = None
341341
"""Optional list of components to render in the modal footer."""
342342

343-
open_trigger: _t.Union[events.PageEvent, None] = _p.Field(default=None)
343+
open_trigger: _t.Union[events.PageEvent, None] = None
344344
"""Optional event to trigger when the modal is opened."""
345345

346-
open_context: _t.Union[events.ContextType, None] = _p.Field(default=None)
346+
open_context: _t.Union[events.ContextType, None] = None
347347
"""Optional context to pass to the open trigger event."""
348348

349349
class_name: _class_name.ClassNameField = None
@@ -359,7 +359,7 @@ class ServerLoad(BaseModel, extra='forbid'):
359359
path: str
360360
"""The URL to load the component from."""
361361

362-
load_trigger: _t.Union[events.PageEvent, None] = _p.Field(default=None)
362+
load_trigger: _t.Union[events.PageEvent, None] = None
363363
"""Optional event to trigger when the component is loaded."""
364364

365365
components: '_t.Union[_t.List[AnyComponent], None]' = None
@@ -368,7 +368,7 @@ class ServerLoad(BaseModel, extra='forbid'):
368368
sse: _t.Union[bool, None] = None
369369
"""Optional flag to enable server-sent events (SSE) for the server load."""
370370

371-
sse_retry: _t.Union[int, None] = _p.Field(default=None)
371+
sse_retry: _t.Union[int, None] = None
372372
"""Optional time in milliseconds to retry the SSE connection."""
373373

374374
method: _t.Union[_t.Literal['GET', 'POST', 'PATCH', 'PUT', 'DELETE'], None] = None
@@ -405,15 +405,15 @@ class Image(BaseModel, extra='forbid'):
405405
'unsafe-url',
406406
],
407407
None,
408-
] = _p.Field(None)
408+
] = None
409409
"""Optional referrer policy for the image. Specifies what information to send when fetching the image.
410410
411411
For more info, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy."""
412412

413413
loading: _t.Union[_t.Literal['eager', 'lazy'], None] = None
414414
"""Optional loading strategy for the image."""
415415

416-
on_click: _t.Union[events.AnyEvent, None] = _p.Field(default=None)
416+
on_click: _t.Union[events.AnyEvent, None] = None
417417
"""Optional event to trigger when the image is clicked."""
418418

419419
class_name: _class_name.ClassNameField = None
@@ -507,7 +507,7 @@ class Error(BaseModel, extra='forbid'):
507507
description: str
508508
"""The description of the error."""
509509

510-
status_code: _t.Union[int, None] = _p.Field(None)
510+
status_code: _t.Union[int, None] = None
511511
"""Optional status code of the error."""
512512

513513
class_name: _class_name.ClassNameField = None
@@ -565,10 +565,10 @@ class Toast(BaseModel, extra='forbid'):
565565
] = None
566566
"""Optional position of the toast."""
567567

568-
open_trigger: _t.Union[events.PageEvent, None] = _p.Field(default=None)
568+
open_trigger: _t.Union[events.PageEvent, None] = None
569569
"""Optional event to trigger when the toast is opened."""
570570

571-
open_context: _t.Union[events.ContextType, None] = _p.Field(default=None)
571+
open_context: _t.Union[events.ContextType, None] = None
572572
"""Optional context to pass to the open trigger event."""
573573

574574
class_name: _class_name.ClassNameField = None

src/python-fastui/fastui/components/display.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class DisplayBase(BaseModel, ABC, defer_build=True):
3838
title: _t.Union[str, None] = None
3939
"""Title to display for the value."""
4040

41-
on_click: _t.Union[events.AnyEvent, None] = pydantic.Field(default=None)
41+
on_click: _t.Union[events.AnyEvent, None] = None
4242
"""Event to trigger when the value is clicked."""
4343

4444

@@ -48,7 +48,7 @@ class DisplayLookup(DisplayBase, extra='forbid'):
4848
field: str
4949
"""Field to display."""
5050

51-
table_width_percent: _t.Union[_te.Annotated[int, _at.Interval(ge=0, le=100)], None] = pydantic.Field(default=None)
51+
table_width_percent: _t.Union[_te.Annotated[int, _at.Interval(ge=0, le=100)], None] = None
5252
"""Percentage width - 0 to 100, specific to tables."""
5353

5454

src/python-fastui/fastui/components/forms.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class BaseFormField(BaseModel, ABC, defer_build=True):
3636
description: _t.Union[str, None] = None
3737
"""Description of the field."""
3838

39-
display_mode: _t.Union[_t.Literal['default', 'inline'], None] = pydantic.Field(default=None)
39+
display_mode: _t.Union[_t.Literal['default', 'inline'], None] = None
4040
"""Display mode for the field."""
4141

4242
class_name: _class_name.ClassNameField = None
@@ -46,7 +46,7 @@ class BaseFormField(BaseModel, ABC, defer_build=True):
4646
class FormFieldInput(BaseFormField):
4747
"""Form field for basic input."""
4848

49-
html_type: InputHtmlType = pydantic.Field(default='text')
49+
html_type: InputHtmlType = 'text'
5050
"""HTML input type for the field."""
5151

5252
initial: _t.Union[str, float, None] = None
@@ -175,13 +175,13 @@ class BaseForm(BaseModel, ABC, defer_build=True, extra='forbid'):
175175
method: _t.Literal['POST', 'GOTO', 'GET'] = 'POST'
176176
"""HTTP method to use for the form submission."""
177177

178-
display_mode: _t.Union[_t.Literal['default', 'page', 'inline'], None] = pydantic.Field(default=None)
178+
display_mode: _t.Union[_t.Literal['default', 'page', 'inline'], None] = None
179179
"""Display mode for the form."""
180180

181-
submit_on_change: _t.Union[bool, None] = pydantic.Field(default=None)
181+
submit_on_change: _t.Union[bool, None] = None
182182
"""Whether to submit the form on change."""
183183

184-
submit_trigger: _t.Union[events.PageEvent, None] = pydantic.Field(default=None)
184+
submit_trigger: _t.Union[events.PageEvent, None] = None
185185
"""Event to trigger form submission."""
186186

187187
loading: '_t.Union[_t.List[AnyComponent], None]' = None

src/python-fastui/fastui/events.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
from typing import Dict, Literal, Union
22

3-
from pydantic import BaseModel, Field
3+
from pydantic import Field
44
from typing_extensions import Annotated, TypeAliasType
55

6+
from .base import BaseModel
7+
68
ContextType = TypeAliasType('ContextType', Dict[str, Union[str, int]])
79

810

911
class PageEvent(BaseModel):
1012
name: str
11-
push_path: Union[str, None] = Field(default=None, serialization_alias='pushPath')
13+
push_path: Union[str, None] = None
1214
context: Union[ContextType, None] = None
1315
clear: Union[bool, None] = None
14-
next_event: 'Union[AnyEvent, None]' = Field(default=None, serialization_alias='nextEvent')
16+
next_event: 'Union[AnyEvent, None]' = None
1517
type: Literal['page'] = 'page'
1618

1719

0 commit comments

Comments
 (0)