{"record":{"id":"4624fc5667f009e0","repo":"Textualize/textual","slug":"value-must-be-a-str","errorCode":null,"errorMessage":"value must be a str","messagePattern":"value must be a str","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/textual/widgets/_digits.py","lineNumber":48,"sourceCode":"        value: str = \"\",\n        *,\n        name: str | None = None,\n        id: str | None = None,\n        classes: str | None = None,\n        disabled: bool = False,\n    ) -> None:\n        \"\"\"Initialize a Digits widget.\n\n        Args:\n            value: Value to display in widget.\n            name: The name of the widget.\n            id: The ID of the widget in the DOM.\n            classes: The CSS classes of the widget.\n            disabled: Whether the widget is disabled or not.\n\n        \"\"\"\n        if not isinstance(value, str):\n            raise TypeError(\"value must be a str\")\n        super().__init__(name=name, id=id, classes=classes, disabled=disabled)\n        self._value = value\n\n    @property\n    def value(self) -> str:\n        \"\"\"The current value displayed in the Digits.\"\"\"\n        return self._value\n\n    def get_selection(self, selection: Selection) -> str | None:\n        return self._value\n\n    def update(self, value: str) -> None:\n        \"\"\"Update the Digits with a new value.\n\n        Args:\n            value: New value to display.\n\n        Raises:","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/widgets/_digits.py#L30-L66","documentation":"A TypeError raised in Digits.__init__ when the value argument is not a str. Digits renders text made of Unicode block characters and has no numeric coercion, so ints/floats must be converted by the caller (e.g. via f-strings or format()).","triggerScenarios":"Constructing Digits(123) or Digits(3.14) with a number; passing bytes; passing a computed numeric value directly from a counter or clock.","commonSituations":"Building clock/counter widgets and passing time.time() or datetime values; assuming Digits works like Input with type coercion.","solutions":["Convert to string first: Digits(str(value)) or Digits(f'{value:.2f}').","For times, format explicitly: Digits(time.strftime('%H:%M:%S')).","Add a type assertion at the call site if value comes from untyped data."],"exampleFix":"# before\ndigits = Digits(12345)\n\n# after\ndigits = Digits(str(12345))","handlingStrategy":"type-guard","validationCode":"value = str(value) if not isinstance(value, str) else value\nDigits(value)","typeGuard":"def is_display_str(value: object) -> bool:\n    return isinstance(value, str)","tryCatchPattern":null,"preventionTips":["Always format numerics with str() or f-strings before passing to Digits","Centralize formatting for clock/counter values"],"tags":["textual","digits","type-error","widget"],"backgroundTag":"wrong-argument-type","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}