{"record":{"id":"0a793f4d79eadbb5","repo":"Textualize/textual","slug":"widget-positional-arguments-must-be-widget-subclas","errorCode":null,"errorMessage":"Widget positional arguments must be Widget subclasses; not {child!r}","messagePattern":"Widget positional arguments must be Widget subclasses; not (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/textual/widget.py","lineNumber":502,"sourceCode":"        self._tooltip: VisualType | None = None\n        \"\"\"The tooltip content.\"\"\"\n        self.absolute_offset: Offset | None = None\n        \"\"\"Force an absolute offset for the widget (used by tooltips).\"\"\"\n\n        self._scrollbar_changes: set[tuple[bool, bool]] = set()\n        \"\"\"Used to stabilize scrollbars.\"\"\"\n        super().__init__(\n            name=name,\n            id=id,\n            classes=self.DEFAULT_CLASSES if classes is None else classes,\n        )\n\n        if self in children:\n            raise WidgetError(\"A widget can't be its own parent\")\n\n        for child in children:\n            if not isinstance(child, Widget):\n                raise TypeError(\n                    f\"Widget positional arguments must be Widget subclasses; not {child!r}\"\n                )\n        self._pending_children = list(children)\n        self.set_reactive(Widget.disabled, disabled)\n        if self.BORDER_TITLE:\n            self.border_title = self.BORDER_TITLE\n        if self.BORDER_SUBTITLE:\n            self.border_subtitle = self.BORDER_SUBTITLE\n\n        self.lock = RLock()\n        \"\"\"`asyncio` lock to be used to synchronize the state of the widget.\n\n        Two different tasks might call methods on a widget at the same time, which\n        might result in a race condition.\n        This can be fixed by adding `async with widget.lock:` around the method calls.\n        \"\"\"\n        self._anchored: bool = False\n        \"\"\"Has this widget been anchored?\"\"\"","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/widget.py#L484-L520","documentation":"Widget's positional constructor arguments must all be Widget instances; anything else (a string, config dict, etc.) raises TypeError listing the offending value.","triggerScenarios":"Widget(\"label\") or Container({\"id\": \"x\"}) — passing strings/dicts positionally, which Widget reserves for child widgets.","commonSituations":"Confusing Widget(children=...) with Static-like content constructors; migrating code that assumed content positional args.","solutions":["Pass content via keyword: Static(\"label\") or widget.update(\"label\")","Wrap non-widget values in an appropriate widget (Label, Static)","Give children as Widget instances only"],"exampleFix":"# before\npanel = Container(\"Settings\")\n# after\npanel = Container(Label(\"Settings\"))","handlingStrategy":"type-guard","validationCode":"if not all(isinstance(c, Widget) for c in children):\n    raise TypeError(\"positional args must be Widgets\")","typeGuard":"def all_widgets(children: list) -> bool:\n    return all(isinstance(c, Widget) for c in children)","tryCatchPattern":null,"preventionTips":["Pass content via keywords, children positionally","Wrap strings in Label/Static"],"tags":["widget","constructor","type-error","textual"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}