pass validation of valid_parent if inheriting from valid class (#3519)

This commit is contained in:
Thomas Brandého 2024-06-19 23:00:18 +02:00 committed by GitHub
parent 6ad679ad66
commit 6709b49cfa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1022,10 +1022,10 @@ class Component(BaseComponent, ABC):
f"The component `{comp_name}` only allows the components: {valid_child_list} as children. Got `{child_name}` instead." f"The component `{comp_name}` only allows the components: {valid_child_list} as children. Got `{child_name}` instead."
) )
if child._valid_parents and comp_name not in [ if child._valid_parents and all(
*child._valid_parents, clz_name not in [*child._valid_parents, *allowed_components]
*allowed_components, for clz_name in self._iter_parent_classes_names()
]: ):
valid_parent_list = ", ".join( valid_parent_list = ", ".join(
[f"`{v_parent}`" for v_parent in child._valid_parents] [f"`{v_parent}`" for v_parent in child._valid_parents]
) )
@ -1153,6 +1153,13 @@ class Component(BaseComponent, ABC):
return True return True
return False return False
@classmethod
def _iter_parent_classes_names(cls) -> Iterator[str]:
for clz in cls.mro():
if clz is Component:
break
yield clz.__name__
@classmethod @classmethod
def _iter_parent_classes_with_method(cls, method: str) -> Iterator[Type[Component]]: def _iter_parent_classes_with_method(cls, method: str) -> Iterator[Type[Component]]:
"""Iterate through parent classes that define a given method. """Iterate through parent classes that define a given method.