From 6d96a94d82aa97028f48ad4da7639483352a64bf Mon Sep 17 00:00:00 2001 From: Benedikt Bartscher Date: Tue, 5 Mar 2024 21:53:44 +0100 Subject: [PATCH] fix chakra list, allow Tag.tag to be None in validation --- reflex/components/chakra/datadisplay/list.py | 19 ++++++++++++++----- reflex/components/tags/tag.py | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/reflex/components/chakra/datadisplay/list.py b/reflex/components/chakra/datadisplay/list.py index d3248e196..a3f8ce8ae 100644 --- a/reflex/components/chakra/datadisplay/list.py +++ b/reflex/components/chakra/datadisplay/list.py @@ -1,17 +1,14 @@ """List components.""" from __future__ import annotations -from typing import Generic, Optional, TypeVar +from typing import Optional from reflex.components.chakra import ChakraComponent from reflex.components.component import Component from reflex.components.core.foreach import Foreach from reflex.vars import Var -T = TypeVar("T") - -# TODO: Generic is just a hacky workaround to stop pydantic from complaining -class List(ChakraComponent, Generic[T]): +class List(ChakraComponent): """Display a list of items.""" tag: str = "List" @@ -25,6 +22,18 @@ class List(ChakraComponent, Generic[T]): # Shorthand prop for listStyleType style_type: Optional[Var[str]] = None + @classmethod + def __class_getitem__(cls, item): + """This method is just a hacky workaround to stop pydantic v2 from complaining. + + Args: + item: The type of the list items. + + Returns: + The list component. + """ + return cls + @classmethod def create( cls, *children, items: list | Var[list] | None = None, **props diff --git a/reflex/components/tags/tag.py b/reflex/components/tags/tag.py index 27b5dc7c1..5f528962c 100644 --- a/reflex/components/tags/tag.py +++ b/reflex/components/tags/tag.py @@ -14,7 +14,7 @@ class Tag(Base): """A React tag.""" # The name of the tag. - name: str = "" + name: str | None = "" # The props of the tag. props: Dict[str, Any] = {}