{"record":{"id":"7406374cef7d0c9e","repo":"Textualize/textual","slug":"no-immediate-child-of-type-expect-type-self-n","errorCode":null,"errorMessage":"No immediate child of type {expect_type}; {self._nodes}","messagePattern":"No immediate child of type (.+?); (.+?)","errorType":"exception","errorClass":"NoMatches","httpStatus":null,"severity":"error","filePath":"src/textual/widget.py","lineNumber":1173,"sourceCode":"        \"\"\"Get the first immediate child of a given type.\n\n        Only returns exact matches, and so will not match subclasses of the given type.\n\n        Args:\n            expect_type: The type of the child to search for.\n\n        Raises:\n            NoMatches: If no matching child is found.\n\n        Returns:\n            The first immediate child widget with the expected type.\n        \"\"\"\n        for child in self._nodes:\n            # We want the child with the exact type (not subclasses)\n            if type(child) is expect_type:\n                assert isinstance(child, expect_type)\n                return child\n        raise NoMatches(f\"No immediate child of type {expect_type}; {self._nodes}\")\n\n    def get_component_rich_style(\n        self, *names: str, partial: bool = False, default: Style | None = None\n    ) -> Style:\n        \"\"\"Get a *Rich* style for a component.\n\n        Args:\n            names: Names of components.\n            partial: Return a partial style (not combined with parent).\n            default: A Style to return if any component style doesn't exist.\n\n        Raises:\n            KeyError: If a component style doesn't exist, and no `default` is provided.\n\n        Returns:\n            A Rich style object.\n        \"\"\"\n","sourceCodeStart":1155,"sourceCodeEnd":1191,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/widget.py#L1155-L1191","documentation":"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.","triggerScenarios":"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.","commonSituations":"Custom widgets wrapping stock widgets (subclass no longer matches), or children added later via mount() so they aren't present yet.","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"],"exampleFix":"# before\nchild = self.get_child_by_type(MyListView)\n# after\nchild = self.query_one(MyListView)","handlingStrategy":"type-guard","validationCode":"if any(type(child) is expect_type for child in self._nodes):\n    child = self.get_child_by_type(expect_type)","typeGuard":"def has_exact_child_type(widget: Widget, t: type) -> bool:\n    return any(type(child) is t for child in widget._nodes)","tryCatchPattern":"try:\n    child = self.get_child_by_type(T)\nexcept NoMatches:\n    child = self.query_one(T)  # subclass-tolerant fallback","preventionTips":["Use query_one(type) when subclasses are possible","Ensure the child is a direct child created in compose()"],"tags":["dom-tree","lookup","type-mismatch","textual"],"backgroundTag":"element-not-found","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}