dangit pydantic

This commit is contained in:
Khaleel Al-Adhami 2024-08-27 16:19:49 -07:00
parent 4f0807ad4b
commit 738eead729
2 changed files with 11 additions and 14 deletions

View File

@ -970,7 +970,6 @@ class App(MiddlewareMixin, LifespanMixin, Base):
f = executor.submit( f = executor.submit(
ExecutorSafeFunctions.compile_unevaluated_page, ExecutorSafeFunctions.compile_unevaluated_page,
route, route,
self.state,
self.style, self.style,
self.theme, self.theme,
) )

View File

@ -106,7 +106,7 @@ def _compile_contexts(state: Optional[Type[BaseState]], theme: Component | None)
def _compile_page( def _compile_page(
component: Component, component: Component,
state: Type[BaseState], state: Type[BaseState] | None,
) -> str: ) -> str:
"""Compile the component given the app state. """Compile the component given the app state.
@ -121,7 +121,7 @@ def _compile_page(
imports = utils.compile_imports(imports) imports = utils.compile_imports(imports)
# Compile the code to render the component. # Compile the code to render the component.
kwargs = {"state_name": state.get_name()} if state else {} kwargs = {"state_name": state.get_name()} if state is not None else {}
return templates.PAGE.render( return templates.PAGE.render(
imports=imports, imports=imports,
@ -403,7 +403,7 @@ def compile_contexts(
def compile_page( def compile_page(
path: str, component: Component, state: Type[BaseState] path: str, component: Component, state: Type[BaseState] | None
) -> tuple[str, str]: ) -> tuple[str, str]:
"""Compile a single page. """Compile a single page.
@ -521,11 +521,11 @@ def compile_unevaluated_page(route: str, page: UnevaluatedPage) -> Component:
"""Compiles an uncompiled page into a component and adds meta information. """Compiles an uncompiled page into a component and adds meta information.
Args: Args:
route (str): The route of the page. route: The route of the page.
page (UncompiledPage): The uncompiled page object. page: The uncompiled page object.
Returns: Returns:
Component: The compiled component. The compiled component.
""" """
# Generate the component if it is a callable. # Generate the component if it is a callable.
component = page.component component = page.component
@ -597,8 +597,6 @@ class ExecutorSafeFunctions:
Args: Args:
route: The route of the page to compile. route: The route of the page to compile.
component: The component to compile.
state: The app state.
Returns: Returns:
The path and code of the compiled page. The path and code of the compiled page.
@ -609,16 +607,13 @@ class ExecutorSafeFunctions:
def compile_unevaluated_page( def compile_unevaluated_page(
cls, cls,
route: str, route: str,
state: Type[BaseState],
style: ComponentStyle, style: ComponentStyle,
theme: Component, theme: Component | None,
) -> tuple[str, Component, tuple[str, str]]: ) -> tuple[str, Component, tuple[str, str]]:
"""Compile an unevaluated page. """Compile an unevaluated page.
Args: Args:
route: The route of the page to compile. route: The route of the page to compile.
page: The unevaluated page.
state: The app state.
style: The style of the page. style: The style of the page.
theme: The theme of the page. theme: The theme of the page.
@ -628,12 +623,15 @@ class ExecutorSafeFunctions:
component = compile_unevaluated_page(route, cls.UNCOMPILED_PAGES[route]) component = compile_unevaluated_page(route, cls.UNCOMPILED_PAGES[route])
component = component if isinstance(component, Component) else component() component = component if isinstance(component, Component) else component()
component._add_style_recursive(style, theme) component._add_style_recursive(style, theme)
return route, component, compile_page(route, component, state) return route, component, compile_page(route, component, cls.STATE)
@classmethod @classmethod
def compile_theme(cls, style: ComponentStyle | None) -> tuple[str, str]: def compile_theme(cls, style: ComponentStyle | None) -> tuple[str, str]:
"""Compile the theme. """Compile the theme.
Args:
style: The style to compile.
Returns: Returns:
The path and code of the compiled theme. The path and code of the compiled theme.