5858)
5959from reflex .vars .function import ArgsFunctionOperation , FunctionStringVar , FunctionVar
6060from reflex .vars .number import ternary_operation
61- from reflex .vars .object import LiteralObjectVar , ObjectVar
61+ from reflex .vars .object import ObjectVar
6262from reflex .vars .sequence import LiteralArrayVar , LiteralStringVar , StringVar
6363
6464
@@ -500,36 +500,16 @@ def _post_init(self, *args, **kwargs):
500500 else :
501501 continue
502502
503- def determine_key (value : Any ):
504- # Try to create a var from the value
505- key = value if isinstance (value , Var ) else LiteralVar .create (value )
506-
507- # Check that the var type is not None.
508- if key is None :
509- raise TypeError
510-
511- return key
512-
513503 # Check whether the key is a component prop.
514504 if is_var :
515505 try :
516- kwargs [key ] = determine_key (value )
506+ kwargs [key ] = LiteralVar . create (value )
517507
508+ # Get the passed type and the var type.
509+ passed_type = kwargs [key ]._var_type
518510 expected_type = types .get_args (
519511 types .get_field_type (type (self ), key )
520512 )[0 ]
521-
522- # validate literal fields.
523- types .validate_literal (
524- key , value , expected_type , type (self ).__name__
525- )
526- # Get the passed type and the var type.
527- passed_type = kwargs [key ]._var_type
528- expected_type = (
529- type (expected_type .__args__ [0 ])
530- if types .is_literal (expected_type )
531- else expected_type
532- )
533513 except TypeError :
534514 # If it is not a valid var, check the base types.
535515 passed_type = type (value )
@@ -561,15 +541,19 @@ def determine_key(value: Any):
561541 kwargs .pop (key , None )
562542
563543 # Place data_ and aria_ attributes into custom_attrs
564- special_attributes = tuple (
544+ special_attributes = [
565545 key
566546 for key in kwargs
567547 if key not in fields and SpecialAttributes .is_special (key )
568- )
548+ ]
569549 if special_attributes :
570550 custom_attrs = kwargs .setdefault ("custom_attrs" , {})
571- for key in special_attributes :
572- custom_attrs [format .to_kebab_case (key )] = kwargs .pop (key )
551+ custom_attrs .update (
552+ {
553+ format .to_kebab_case (key ): kwargs .pop (key )
554+ for key in special_attributes
555+ }
556+ )
573557
574558 # Add style props to the component.
575559 style = kwargs .get ("style" , {})
@@ -805,6 +789,18 @@ def _get_components_in_props(self) -> Sequence[BaseComponent]:
805789 for component in _components_from (value )
806790 ]
807791
792+ @classmethod
793+ def _validate_children (cls , children : tuple | list ):
794+ from reflex .utils .exceptions import ChildrenTypeError
795+
796+ for child in children :
797+ if isinstance (child , (tuple , list )):
798+ cls ._validate_children (child )
799+
800+ # Make sure the child is a valid type.
801+ if isinstance (child , dict ) or not isinstance (child , ComponentChildTypes ):
802+ raise ChildrenTypeError (component = cls .__name__ , child = child )
803+
808804 @classmethod
809805 def create (cls : type [T ], * children , ** props ) -> T :
810806 """Create the component.
@@ -819,24 +815,12 @@ def create(cls: type[T], *children, **props) -> T:
819815 # Import here to avoid circular imports.
820816 from reflex .components .base .bare import Bare
821817 from reflex .components .base .fragment import Fragment
822- from reflex .utils .exceptions import ChildrenTypeError
823818
824819 # Filter out None props
825820 props = {key : value for key , value in props .items () if value is not None }
826821
827- def validate_children (children : tuple | list ):
828- for child in children :
829- if isinstance (child , (tuple , list )):
830- validate_children (child )
831-
832- # Make sure the child is a valid type.
833- if isinstance (child , dict ) or not isinstance (
834- child , ComponentChildTypes
835- ):
836- raise ChildrenTypeError (component = cls .__name__ , child = child )
837-
838822 # Validate all the children.
839- validate_children (children )
823+ cls . _validate_children (children )
840824
841825 children_normalized = [
842826 (
@@ -2577,25 +2561,7 @@ def render_dict_to_var(tag: dict | Component | str, imported_names: set[str]) ->
25772561 else LiteralNoneVar .create (),
25782562 )
25792563
2580- props = {}
2581-
2582- special_props = []
2583-
2584- for prop_str in tag ["props" ]:
2585- if ":" not in prop_str :
2586- special_props .append (Var (prop_str ).to (ObjectVar ))
2587- continue
2588- prop = prop_str .index (":" )
2589- key = prop_str [:prop ]
2590- value = prop_str [prop + 1 :]
2591- props [key ] = value
2592-
2593- props = LiteralObjectVar .create (
2594- {LiteralStringVar .create (k ): Var (v ) for k , v in props .items ()}
2595- )
2596-
2597- for prop in special_props :
2598- props = props .merge (prop )
2564+ props = Var ("({" + "," .join (tag ["props" ]) + "})" )
25992565
26002566 contents = tag ["contents" ] if tag ["contents" ] else None
26012567
0 commit comments