Textualize/textual · error · NoMatches
No immediate child of type {expect_type}; {self._nodes}
Error message
No immediate child of type {expect_type}; {self._nodes} What it means
get_child_by_type requires an immediate child whose exact type (type(child) is expect_type, not a subclass) matches; NoMatches lists the actual children for debugging when none matches.
Source
Thrown at src/textual/widget.py:1173
"""Get the first immediate child of a given type.
Only returns exact matches, and so will not match subclasses of the given type.
Args:
expect_type: The type of the child to search for.
Raises:
NoMatches: If no matching child is found.
Returns:
The first immediate child widget with the expected type.
"""
for child in self._nodes:
# We want the child with the exact type (not subclasses)
if type(child) is expect_type:
assert isinstance(child, expect_type)
return child
raise NoMatches(f"No immediate child of type {expect_type}; {self._nodes}")
def get_component_rich_style(
self, *names: str, partial: bool = False, default: Style | None = None
) -> Style:
"""Get a *Rich* style for a component.
Args:
names: Names of components.
partial: Return a partial style (not combined with parent).
default: A Style to return if any component style doesn't exist.
Raises:
KeyError: If a component style doesn't exist, and no `default` is provided.
Returns:
A Rich style object.
"""
View on GitHub (pinned to 06dbeef4bb)
Solutions
- Use query_one with a type selector, which matches subclasses: query_one(ListView)
- Ensure the child is created in compose() as a direct child of this widget
- If mounted dynamically, wait for mount (call_after_refresh) before lookup
Example fix
# before child = self.get_child_by_type(MyListView) # after child = self.query_one(MyListView)
Defensive patterns
Strategy: type-guard
Validate before calling
if any(type(child) is expect_type for child in self._nodes):
child = self.get_child_by_type(expect_type) Type guard
def has_exact_child_type(widget: Widget, t: type) -> bool:
return any(type(child) is t for child in widget._nodes) Try / catch
try:
child = self.get_child_by_type(T)
except NoMatches:
child = self.query_one(T) # subclass-tolerant fallback Prevention
- Use query_one(type) when subclasses are possible
- Ensure the child is a direct child created in compose()
When it happens
Trigger: Calling get_child_by_type(ListView) when the child is a subclass of ListView, a different type, or the child lives deeper than one level.
Common situations: Custom widgets wrapping stock widgets (subclass no longer matches), or children added later via mount() so they aren't present yet.
Related errors
- No child found with id={id!r}
- Child with id={id!r} is the wrong type; expected type {expec
- Descendant with id={id!r} is the wrong type; expected type {
- Don't know how to animate {value!r}; Can only animate <int>,
- Can't encode {datum!r}
AI-assisted analysis of Textualize/textual@06dbeef4bb (2026-08-27).
Data as JSON: /api/errors/7406374cef7d0c9e.
Report an issue: GitHub.