MCPcopy Index your code
hub / github.com/plotly/dash / get_children

Function get_children

dash/_layout_utils.py:66–96  ·  view source on GitHub ↗

Resolve a ``_children_props`` path expression to child Components. Mirrors the dash-renderer's path parsing in ``DashWrapper.tsx``. Supports: - ``"children"`` — simple prop - ``"control_groups[].children"`` — array, then sub-prop per element - ``"insights.title"`` — nested objec

(component: Any, prop_path: str)

Source from the content-addressed store, hash-verified

64
65
66def get_children(component: Any, prop_path: str) -> list[Component]:
67 """Resolve a ``_children_props`` path expression to child Components.
68
69 Mirrors the dash-renderer's path parsing in ``DashWrapper.tsx``.
70 Supports:
71 - ``"children"`` — simple prop
72 - ``"control_groups[].children"`` — array, then sub-prop per element
73 - ``"insights.title"`` — nested object prop
74 """
75 clean_path = prop_path.replace("[]", "").replace("{}", "")
76
77 if "." not in prop_path:
78 return _collect_components(getattr(component, clean_path, None))
79
80 parts = prop_path.split(".")
81 array_idx = next((i for i, p in enumerate(parts) if "[]" in p), len(parts))
82 front = [p.replace("[]", "").replace("{}", "") for p in parts[: array_idx + 1]]
83 back = [p.replace("{}", "") for p in parts[array_idx + 1 :]]
84
85 node = _resolve_path(component, front)
86 if node is None:
87 return []
88
89 if back and isinstance(node, (list, tuple)):
90 results: list[Component] = []
91 for element in node:
92 child = _resolve_path(element, back)
93 results.extend(_collect_components(child))
94 return results
95
96 return _collect_components(node)
97
98
99def _resolve_path(node: Any, keys: list[str]) -> Any:

Callers 1

iter_childrenFunction · 0.85

Calls 3

_collect_componentsFunction · 0.85
_resolve_pathFunction · 0.85
extendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…