Do some magic for the subclass initialization. Args: mixin: Whether the subclass is a mixin and should not be initialized. **kwargs: The kwargs to pass to the init_subclass method. Raises: StateValueError: If a substate class shadows another.
(cls, mixin: bool = False, **kwargs)
| 531 | |
| 532 | @classmethod |
| 533 | def __init_subclass__(cls, mixin: bool = False, **kwargs): |
| 534 | """Do some magic for the subclass initialization. |
| 535 | |
| 536 | Args: |
| 537 | mixin: Whether the subclass is a mixin and should not be initialized. |
| 538 | **kwargs: The kwargs to pass to the init_subclass method. |
| 539 | |
| 540 | Raises: |
| 541 | StateValueError: If a substate class shadows another. |
| 542 | """ |
| 543 | from reflex_base.registry import RegistrationContext |
| 544 | from reflex_base.utils.exceptions import StateValueError |
| 545 | |
| 546 | super().__init_subclass__(**kwargs) |
| 547 | |
| 548 | if cls._mixin: |
| 549 | return |
| 550 | |
| 551 | # Handle locally-defined states for pickling. |
| 552 | if "<locals>" in cls.__qualname__: |
| 553 | cls._handle_local_def() |
| 554 | |
| 555 | # Validate the module name. |
| 556 | cls._validate_module_name() |
| 557 | |
| 558 | # Event handlers should not shadow builtin state methods. |
| 559 | cls._check_overridden_methods() |
| 560 | |
| 561 | # Computed vars should not shadow builtin state props. |
| 562 | cls._check_overridden_basevars() |
| 563 | |
| 564 | # Reset dirty substate tracking for this class. |
| 565 | cls._always_dirty_substates = set() |
| 566 | cls._potentially_dirty_states = set() |
| 567 | |
| 568 | # Get the parent vars. |
| 569 | parent_state = cls.get_parent_state() |
| 570 | if parent_state is not None: |
| 571 | cls.inherited_vars = parent_state.vars |
| 572 | cls.inherited_backend_vars = parent_state.backend_vars |
| 573 | |
| 574 | # Check if another substate class with the same name has already been defined. |
| 575 | if cls.get_name() in {c.get_name() for c in parent_state.get_substates()}: |
| 576 | # This should not happen, since we have added module prefix to state names in #3214 |
| 577 | msg = ( |
| 578 | f"The substate class '{cls.get_name()}' has been defined multiple times. " |
| 579 | "Shadowing substate classes is not allowed." |
| 580 | ) |
| 581 | raise StateValueError(msg) |
| 582 | |
| 583 | # A descriptor defined directly on this class overrides any same-named |
| 584 | # entry inherited from a parent state. Drop those names from the |
| 585 | # inherited maps so backend var assembly, dependency tracking, and the |
| 586 | # __setattr__ routing all resolve to the descriptor on this class. |
| 587 | hints = cls._get_type_hints() |
| 588 | own_descriptor_names = { |
| 589 | name |
| 590 | for name, value in cls.__dict__.items() |
no test coverage detected