From a4edf692ef28481edf080c61f4cc38510df65e68 Mon Sep 17 00:00:00 2001 From: Alek Petuskey Date: Wed, 26 Jun 2024 13:12:33 -0700 Subject: [PATCH 1/6] Better type strategy prop --- reflex/components/base/script.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reflex/components/base/script.py b/reflex/components/base/script.py index 3aef867d4d..055a7eb5c1 100644 --- a/reflex/components/base/script.py +++ b/reflex/components/base/script.py @@ -5,6 +5,7 @@ from __future__ import annotations +from typing import Literal from reflex.components.component import Component from reflex.event import EventHandler from reflex.vars import Var @@ -28,7 +29,7 @@ class Script(Component): src: Var[str] # When the script will execute: afterInteractive | beforeInteractive | lazyOnload - strategy: Var[str] = "afterInteractive" # type: ignore + strategy: Var[Literal["afterInteractive", "beforeInteractive", "lazyOnload"]] = "afterInteractive" # Triggered when the script is loading on_load: EventHandler[lambda: []] From a509b6ceb9a1b3e37f60ccd35e301cfa02f575a0 Mon Sep 17 00:00:00 2001 From: Alek Petuskey Date: Wed, 26 Jun 2024 13:15:52 -0700 Subject: [PATCH 2/6] Add beter description --- reflex/components/base/script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reflex/components/base/script.py b/reflex/components/base/script.py index 055a7eb5c1..b03f64663d 100644 --- a/reflex/components/base/script.py +++ b/reflex/components/base/script.py @@ -28,7 +28,7 @@ class Script(Component): # Required unless inline script is used src: Var[str] - # When the script will execute: afterInteractive | beforeInteractive | lazyOnload + # When the script will execute: afterInteractive (defer-like behavior) | beforeInteractive | lazyOnload (async-like behavior) strategy: Var[Literal["afterInteractive", "beforeInteractive", "lazyOnload"]] = "afterInteractive" # Triggered when the script is loading From 21533124c999a582215b2f98c3b68429cfbbb1f6 Mon Sep 17 00:00:00 2001 From: Alek Petuskey Date: Wed, 26 Jun 2024 13:29:23 -0700 Subject: [PATCH 3/6] Pre commit --- reflex/components/base/script.py | 5 ++++- reflex/components/base/script.pyi | 10 ++++++++-- reflex/components/chakra/base.pyi | 1 - reflex/components/chakra/datadisplay/table.pyi | 3 --- reflex/components/core/banner.pyi | 1 - reflex/components/core/clipboard.py | 1 + reflex/components/datadisplay/code.pyi | 1 - reflex/components/el/elements/__init__.pyi | 2 +- reflex/components/el/elements/forms.pyi | 1 - reflex/components/gridjs/datatable.pyi | 1 - reflex/components/markdown/markdown.pyi | 1 - reflex/components/radix/primitives/accordion.pyi | 4 ---- reflex/components/radix/themes/base.pyi | 1 - .../components/radix/themes/components/icon_button.pyi | 1 - reflex/components/radix/themes/components/tabs.pyi | 1 - .../components/radix/themes/components/text_field.pyi | 1 - reflex/components/radix/themes/layout/list.pyi | 1 - 17 files changed, 14 insertions(+), 22 deletions(-) diff --git a/reflex/components/base/script.py b/reflex/components/base/script.py index b03f64663d..80cc766b01 100644 --- a/reflex/components/base/script.py +++ b/reflex/components/base/script.py @@ -6,6 +6,7 @@ from __future__ import annotations from typing import Literal + from reflex.components.component import Component from reflex.event import EventHandler from reflex.vars import Var @@ -29,7 +30,9 @@ class Script(Component): src: Var[str] # When the script will execute: afterInteractive (defer-like behavior) | beforeInteractive | lazyOnload (async-like behavior) - strategy: Var[Literal["afterInteractive", "beforeInteractive", "lazyOnload"]] = "afterInteractive" + strategy: Var[Literal["afterInteractive", "beforeInteractive", "lazyOnload"]] = ( + "afterInteractive" + ) # Triggered when the script is loading on_load: EventHandler[lambda: []] diff --git a/reflex/components/base/script.pyi b/reflex/components/base/script.pyi index f5bcb93546..1549ffda6a 100644 --- a/reflex/components/base/script.pyi +++ b/reflex/components/base/script.pyi @@ -7,6 +7,7 @@ from typing import Any, Dict, Literal, Optional, Union, overload from reflex.vars import Var, BaseVar, ComputedVar from reflex.event import EventChain, EventHandler, EventSpec from reflex.style import Style +from typing import Literal from reflex.components.component import Component from reflex.event import EventHandler from reflex.vars import Var @@ -18,7 +19,12 @@ class Script(Component): cls, *children, src: Optional[Union[Var[str], str]] = None, - strategy: Optional[Union[Var[str], str]] = None, + strategy: Optional[ + Union[ + Var[Literal["afterInteractive", "beforeInteractive", "lazyOnload"]], + Literal["afterInteractive", "beforeInteractive", "lazyOnload"], + ] + ] = None, style: Optional[Style] = None, key: Optional[Any] = None, id: Optional[Any] = None, @@ -96,7 +102,7 @@ class Script(Component): Args: *children: The children of the component. src: Required unless inline script is used - strategy: When the script will execute: afterInteractive | beforeInteractive | lazyOnload + strategy: When the script will execute: afterInteractive (defer-like behavior) | beforeInteractive | lazyOnload (async-like behavior) style: The style of the component. key: A unique key for the component. id: The id for the component. diff --git a/reflex/components/chakra/base.pyi b/reflex/components/chakra/base.pyi index b922474317..d209e48fb3 100644 --- a/reflex/components/chakra/base.pyi +++ b/reflex/components/chakra/base.pyi @@ -155,7 +155,6 @@ class ChakraProvider(ChakraComponent): A new ChakraProvider component. """ ... - def add_imports(self) -> ImportDict: ... chakra_provider = ChakraProvider.create() diff --git a/reflex/components/chakra/datadisplay/table.pyi b/reflex/components/chakra/datadisplay/table.pyi index de352584c2..5a271d259c 100644 --- a/reflex/components/chakra/datadisplay/table.pyi +++ b/reflex/components/chakra/datadisplay/table.pyi @@ -184,7 +184,6 @@ class Thead(ChakraComponent): """ ... - @staticmethod def validate_headers(headers): ... @@ -265,7 +264,6 @@ class Tbody(ChakraComponent): Component: The table body component """ ... - @staticmethod def validate_rows(rows): ... @@ -346,7 +344,6 @@ class Tfoot(ChakraComponent): The table footer component. """ ... - @staticmethod def validate_footers(footers): ... diff --git a/reflex/components/core/banner.pyi b/reflex/components/core/banner.pyi index f38a4571fe..c957bab932 100644 --- a/reflex/components/core/banner.pyi +++ b/reflex/components/core/banner.pyi @@ -445,7 +445,6 @@ class WifiOffPulse(Icon): The icon component with default props applied. """ ... - def add_imports(self) -> dict[str, str | ImportVar | list[str | ImportVar]]: ... class ConnectionPulser(Div): diff --git a/reflex/components/core/clipboard.py b/reflex/components/core/clipboard.py index 3ffc4e77a2..9b0edcc293 100644 --- a/reflex/components/core/clipboard.py +++ b/reflex/components/core/clipboard.py @@ -1,4 +1,5 @@ """Global on_paste handling for Reflex app.""" + from __future__ import annotations from typing import Dict, List, Union diff --git a/reflex/components/datadisplay/code.pyi b/reflex/components/datadisplay/code.pyi index 92d14d447d..a4607c1010 100644 --- a/reflex/components/datadisplay/code.pyi +++ b/reflex/components/datadisplay/code.pyi @@ -1112,7 +1112,6 @@ class CodeBlock(Component): The text component. """ ... - def add_style(self): ... @staticmethod def convert_theme_name(theme) -> str: ... diff --git a/reflex/components/el/elements/__init__.pyi b/reflex/components/el/elements/__init__.pyi index 527923b21c..d0fbfd5ac9 100644 --- a/reflex/components/el/elements/__init__.pyi +++ b/reflex/components/el/elements/__init__.pyi @@ -349,5 +349,5 @@ _MAPPING = { ], } EXCLUDE = ["del_", "Del", "image"] -for _, v in _MAPPING.items(): +for (_, v) in _MAPPING.items(): v.extend([mod.capitalize() for mod in v if mod not in EXCLUDE]) diff --git a/reflex/components/el/elements/forms.pyi b/reflex/components/el/elements/forms.pyi index 32a2609ee8..b400058a19 100644 --- a/reflex/components/el/elements/forms.pyi +++ b/reflex/components/el/elements/forms.pyi @@ -580,7 +580,6 @@ class Form(BaseHTML): The form component. """ ... - def add_imports(self) -> ImportDict: ... def add_hooks(self) -> list[str]: ... diff --git a/reflex/components/gridjs/datatable.pyi b/reflex/components/gridjs/datatable.pyi index 5766661f1b..13a7131e71 100644 --- a/reflex/components/gridjs/datatable.pyi +++ b/reflex/components/gridjs/datatable.pyi @@ -181,5 +181,4 @@ class DataTable(Gridjs): ValueError: If a pandas dataframe is passed in and columns are also provided. """ ... - def add_imports(self) -> ImportDict: ... diff --git a/reflex/components/markdown/markdown.pyi b/reflex/components/markdown/markdown.pyi index 020152d15d..5b2968bf5e 100644 --- a/reflex/components/markdown/markdown.pyi +++ b/reflex/components/markdown/markdown.pyi @@ -123,7 +123,6 @@ class Markdown(Component): The markdown component. """ ... - def add_imports(self) -> ImportDict | list[ImportDict]: ... def get_component(self, tag: str, **props) -> Component: ... def format_component(self, tag: str, **props) -> str: ... diff --git a/reflex/components/radix/primitives/accordion.pyi b/reflex/components/radix/primitives/accordion.pyi index 58c1ed31dd..44d14d96e4 100644 --- a/reflex/components/radix/primitives/accordion.pyi +++ b/reflex/components/radix/primitives/accordion.pyi @@ -519,7 +519,6 @@ class AccordionItem(AccordionComponent): The accordion item. """ ... - def add_style(self) -> dict[str, Any] | None: ... class AccordionHeader(AccordionComponent): @@ -669,7 +668,6 @@ class AccordionHeader(AccordionComponent): The Accordion header Component. """ ... - def add_style(self) -> dict[str, Any] | None: ... class AccordionTrigger(AccordionComponent): @@ -819,7 +817,6 @@ class AccordionTrigger(AccordionComponent): The Accordion trigger Component. """ ... - def add_style(self) -> dict[str, Any] | None: ... class AccordionIcon(Icon): @@ -1048,7 +1045,6 @@ class AccordionContent(AccordionComponent): The Accordion content Component. """ ... - def add_custom_code(self) -> list[str]: ... def add_style(self) -> dict[str, Any] | None: ... diff --git a/reflex/components/radix/themes/base.pyi b/reflex/components/radix/themes/base.pyi index a458710ca0..14ed8f7c30 100644 --- a/reflex/components/radix/themes/base.pyi +++ b/reflex/components/radix/themes/base.pyi @@ -580,7 +580,6 @@ class Theme(RadixThemesComponent): A new component instance. """ ... - def add_imports(self) -> ImportDict | list[ImportDict]: ... class ThemePanel(RadixThemesComponent): diff --git a/reflex/components/radix/themes/components/icon_button.pyi b/reflex/components/radix/themes/components/icon_button.pyi index a7d56b5172..0eb51721d0 100644 --- a/reflex/components/radix/themes/components/icon_button.pyi +++ b/reflex/components/radix/themes/components/icon_button.pyi @@ -281,7 +281,6 @@ class IconButton(elements.Button, RadixLoadingProp, RadixThemesComponent): The IconButton component. """ ... - def add_style(self): ... icon_button = IconButton.create diff --git a/reflex/components/radix/themes/components/tabs.pyi b/reflex/components/radix/themes/components/tabs.pyi index 422ca8b66d..6d11c10acf 100644 --- a/reflex/components/radix/themes/components/tabs.pyi +++ b/reflex/components/radix/themes/components/tabs.pyi @@ -334,7 +334,6 @@ class TabsTrigger(RadixThemesComponent): The TabsTrigger Component. """ ... - def add_style(self) -> Dict[str, Any] | None: ... class TabsContent(RadixThemesComponent): diff --git a/reflex/components/radix/themes/components/text_field.pyi b/reflex/components/radix/themes/components/text_field.pyi index 531bf623ee..a74ab91776 100644 --- a/reflex/components/radix/themes/components/text_field.pyi +++ b/reflex/components/radix/themes/components/text_field.pyi @@ -266,7 +266,6 @@ class TextFieldRoot(elements.Div, RadixThemesComponent): The component. """ ... - @classmethod def create_root_deprecated(cls, *children, **props) -> Component: ... @classmethod diff --git a/reflex/components/radix/themes/layout/list.pyi b/reflex/components/radix/themes/layout/list.pyi index 70928db5d6..eca3a7ec4d 100644 --- a/reflex/components/radix/themes/layout/list.pyi +++ b/reflex/components/radix/themes/layout/list.pyi @@ -156,7 +156,6 @@ class BaseList(Component): """ ... - def add_style(self) -> dict[str, Any] | None: ... class UnorderedList(BaseList, Ul): From 2ae1063ea178565b92d0ac2486d5eccc278a4e15 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Thu, 27 Jun 2024 16:00:57 -0700 Subject: [PATCH 4/6] fix pyi generation --- reflex/components/chakra/base.pyi | 1 + reflex/components/chakra/datadisplay/table.pyi | 3 +++ reflex/components/core/banner.pyi | 1 + reflex/components/datadisplay/code.pyi | 1 + reflex/components/el/elements/__init__.pyi | 2 +- reflex/components/el/elements/forms.pyi | 1 + reflex/components/gridjs/datatable.pyi | 1 + reflex/components/markdown/markdown.pyi | 1 + reflex/components/radix/primitives/accordion.pyi | 4 ++++ reflex/components/radix/themes/base.pyi | 1 + reflex/components/radix/themes/components/icon_button.pyi | 1 + reflex/components/radix/themes/components/tabs.pyi | 1 + reflex/components/radix/themes/components/text_field.pyi | 1 + reflex/components/radix/themes/layout/list.pyi | 1 + 14 files changed, 19 insertions(+), 1 deletion(-) diff --git a/reflex/components/chakra/base.pyi b/reflex/components/chakra/base.pyi index d209e48fb3..b922474317 100644 --- a/reflex/components/chakra/base.pyi +++ b/reflex/components/chakra/base.pyi @@ -155,6 +155,7 @@ class ChakraProvider(ChakraComponent): A new ChakraProvider component. """ ... + def add_imports(self) -> ImportDict: ... chakra_provider = ChakraProvider.create() diff --git a/reflex/components/chakra/datadisplay/table.pyi b/reflex/components/chakra/datadisplay/table.pyi index 5a271d259c..de352584c2 100644 --- a/reflex/components/chakra/datadisplay/table.pyi +++ b/reflex/components/chakra/datadisplay/table.pyi @@ -184,6 +184,7 @@ class Thead(ChakraComponent): """ ... + @staticmethod def validate_headers(headers): ... @@ -264,6 +265,7 @@ class Tbody(ChakraComponent): Component: The table body component """ ... + @staticmethod def validate_rows(rows): ... @@ -344,6 +346,7 @@ class Tfoot(ChakraComponent): The table footer component. """ ... + @staticmethod def validate_footers(footers): ... diff --git a/reflex/components/core/banner.pyi b/reflex/components/core/banner.pyi index 41b4358d94..1cb7d05b03 100644 --- a/reflex/components/core/banner.pyi +++ b/reflex/components/core/banner.pyi @@ -445,6 +445,7 @@ class WifiOffPulse(Icon): The icon component with default props applied. """ ... + def add_imports(self) -> dict[str, str | ImportVar | list[str | ImportVar]]: ... class ConnectionPulser(Div): diff --git a/reflex/components/datadisplay/code.pyi b/reflex/components/datadisplay/code.pyi index e270c805a0..ba40700fdc 100644 --- a/reflex/components/datadisplay/code.pyi +++ b/reflex/components/datadisplay/code.pyi @@ -1112,6 +1112,7 @@ class CodeBlock(Component): The text component. """ ... + def add_style(self): ... @staticmethod def convert_theme_name(theme) -> str: ... diff --git a/reflex/components/el/elements/__init__.pyi b/reflex/components/el/elements/__init__.pyi index d0fbfd5ac9..527923b21c 100644 --- a/reflex/components/el/elements/__init__.pyi +++ b/reflex/components/el/elements/__init__.pyi @@ -349,5 +349,5 @@ _MAPPING = { ], } EXCLUDE = ["del_", "Del", "image"] -for (_, v) in _MAPPING.items(): +for _, v in _MAPPING.items(): v.extend([mod.capitalize() for mod in v if mod not in EXCLUDE]) diff --git a/reflex/components/el/elements/forms.pyi b/reflex/components/el/elements/forms.pyi index a8bd6aa89b..0694c59740 100644 --- a/reflex/components/el/elements/forms.pyi +++ b/reflex/components/el/elements/forms.pyi @@ -580,6 +580,7 @@ class Form(BaseHTML): The form component. """ ... + def add_imports(self) -> ImportDict: ... def add_hooks(self) -> list[str]: ... diff --git a/reflex/components/gridjs/datatable.pyi b/reflex/components/gridjs/datatable.pyi index 7176b43f26..e80cbafa7b 100644 --- a/reflex/components/gridjs/datatable.pyi +++ b/reflex/components/gridjs/datatable.pyi @@ -181,4 +181,5 @@ class DataTable(Gridjs): ValueError: If a pandas dataframe is passed in and columns are also provided. """ ... + def add_imports(self) -> ImportDict: ... diff --git a/reflex/components/markdown/markdown.pyi b/reflex/components/markdown/markdown.pyi index 5b2968bf5e..020152d15d 100644 --- a/reflex/components/markdown/markdown.pyi +++ b/reflex/components/markdown/markdown.pyi @@ -123,6 +123,7 @@ class Markdown(Component): The markdown component. """ ... + def add_imports(self) -> ImportDict | list[ImportDict]: ... def get_component(self, tag: str, **props) -> Component: ... def format_component(self, tag: str, **props) -> str: ... diff --git a/reflex/components/radix/primitives/accordion.pyi b/reflex/components/radix/primitives/accordion.pyi index fc751e6b55..8ae49be9f5 100644 --- a/reflex/components/radix/primitives/accordion.pyi +++ b/reflex/components/radix/primitives/accordion.pyi @@ -519,6 +519,7 @@ class AccordionItem(AccordionComponent): The accordion item. """ ... + def add_style(self) -> dict[str, Any] | None: ... class AccordionHeader(AccordionComponent): @@ -668,6 +669,7 @@ class AccordionHeader(AccordionComponent): The Accordion header Component. """ ... + def add_style(self) -> dict[str, Any] | None: ... class AccordionTrigger(AccordionComponent): @@ -817,6 +819,7 @@ class AccordionTrigger(AccordionComponent): The Accordion trigger Component. """ ... + def add_style(self) -> dict[str, Any] | None: ... class AccordionIcon(Icon): @@ -1045,6 +1048,7 @@ class AccordionContent(AccordionComponent): The Accordion content Component. """ ... + def add_custom_code(self) -> list[str]: ... def add_style(self) -> dict[str, Any] | None: ... diff --git a/reflex/components/radix/themes/base.pyi b/reflex/components/radix/themes/base.pyi index 14ed8f7c30..a458710ca0 100644 --- a/reflex/components/radix/themes/base.pyi +++ b/reflex/components/radix/themes/base.pyi @@ -580,6 +580,7 @@ class Theme(RadixThemesComponent): A new component instance. """ ... + def add_imports(self) -> ImportDict | list[ImportDict]: ... class ThemePanel(RadixThemesComponent): diff --git a/reflex/components/radix/themes/components/icon_button.pyi b/reflex/components/radix/themes/components/icon_button.pyi index 8ec81be6fa..5af58dc332 100644 --- a/reflex/components/radix/themes/components/icon_button.pyi +++ b/reflex/components/radix/themes/components/icon_button.pyi @@ -281,6 +281,7 @@ class IconButton(elements.Button, RadixLoadingProp, RadixThemesComponent): The IconButton component. """ ... + def add_style(self): ... icon_button = IconButton.create diff --git a/reflex/components/radix/themes/components/tabs.pyi b/reflex/components/radix/themes/components/tabs.pyi index a1861e1781..c8ee749bb8 100644 --- a/reflex/components/radix/themes/components/tabs.pyi +++ b/reflex/components/radix/themes/components/tabs.pyi @@ -342,6 +342,7 @@ class TabsTrigger(RadixThemesComponent): The TabsTrigger Component. """ ... + def add_style(self) -> Dict[str, Any] | None: ... class TabsContent(RadixThemesComponent): diff --git a/reflex/components/radix/themes/components/text_field.pyi b/reflex/components/radix/themes/components/text_field.pyi index 591bd23aeb..7270f10769 100644 --- a/reflex/components/radix/themes/components/text_field.pyi +++ b/reflex/components/radix/themes/components/text_field.pyi @@ -266,6 +266,7 @@ class TextFieldRoot(elements.Div, RadixThemesComponent): The component. """ ... + @classmethod def create_root_deprecated(cls, *children, **props) -> Component: ... @classmethod diff --git a/reflex/components/radix/themes/layout/list.pyi b/reflex/components/radix/themes/layout/list.pyi index 2724d53332..976553db0b 100644 --- a/reflex/components/radix/themes/layout/list.pyi +++ b/reflex/components/radix/themes/layout/list.pyi @@ -156,6 +156,7 @@ class BaseList(Component): """ ... + def add_style(self) -> dict[str, Any] | None: ... class UnorderedList(BaseList, Ul): From 5bc43823e1f2fb5bc6326f4eab137ee99d65c5a2 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Fri, 28 Jun 2024 11:16:14 -0700 Subject: [PATCH 5/6] Default prop assignment must be Var to pass type checking --- reflex/components/base/script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reflex/components/base/script.py b/reflex/components/base/script.py index 80cc766b01..bef2f036b3 100644 --- a/reflex/components/base/script.py +++ b/reflex/components/base/script.py @@ -31,7 +31,7 @@ class Script(Component): # When the script will execute: afterInteractive (defer-like behavior) | beforeInteractive | lazyOnload (async-like behavior) strategy: Var[Literal["afterInteractive", "beforeInteractive", "lazyOnload"]] = ( - "afterInteractive" + Var.create_safe("afterInteractive", _var_is_string=True) ) # Triggered when the script is loading From d3291c81a17b945503da84b44af26383de122e75 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Fri, 28 Jun 2024 17:29:34 -0700 Subject: [PATCH 6/6] fix script.pyi --- reflex/components/base/script.pyi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/reflex/components/base/script.pyi b/reflex/components/base/script.pyi index c090225912..9ed757cfe7 100644 --- a/reflex/components/base/script.pyi +++ b/reflex/components/base/script.pyi @@ -22,7 +22,9 @@ class Script(Component): src: Optional[Union[reflex.vars.Var[str], str]] = None, strategy: Optional[ Union[ - reflex.vars.Var[Literal["afterInteractive", "beforeInteractive", "lazyOnload"]], + reflex.vars.Var[ + Literal["afterInteractive", "beforeInteractive", "lazyOnload"] + ], Literal["afterInteractive", "beforeInteractive", "lazyOnload"], ] ] = None,