{"record":{"id":"5f3abc2ccf768240","repo":"Textualize/rich","slug":"expected-at-least-one-non-none-style","errorCode":null,"errorMessage":"expected at least one non-None style","messagePattern":"expected at least one non-None style","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"rich/style.py","lineNumber":410,"sourceCode":"\n        Args:\n            style (str): A style definition.\n\n        Returns:\n            str: Normal form of style definition.\n        \"\"\"\n        try:\n            return str(cls.parse(style))\n        except errors.StyleSyntaxError:\n            return style.strip().lower()\n\n    @classmethod\n    def pick_first(cls, *values: Optional[StyleType]) -> StyleType:\n        \"\"\"Pick first non-None style.\"\"\"\n        for value in values:\n            if value is not None:\n                return value\n        raise ValueError(\"expected at least one non-None style\")\n\n    def __rich_repr__(self) -> Result:\n        yield \"color\", self.color, None\n        yield \"bgcolor\", self.bgcolor, None\n        yield \"bold\", self.bold, None,\n        yield \"dim\", self.dim, None,\n        yield \"italic\", self.italic, None\n        yield \"underline\", self.underline, None,\n        yield \"blink\", self.blink, None\n        yield \"blink2\", self.blink2, None\n        yield \"reverse\", self.reverse, None\n        yield \"conceal\", self.conceal, None\n        yield \"strike\", self.strike, None\n        yield \"underline2\", self.underline2, None\n        yield \"frame\", self.frame, None\n        yield \"encircle\", self.encircle, None\n        yield \"link\", self.link, None\n        if self._meta:","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/Textualize/rich/blob/9d8f9a372cc5916fd4781fec207ced7ddac2f08f/rich/style.py#L392-L428","documentation":"Style.pick_first(*values) is a classmethod convenience that returns the first non-None argument, letting callers express 'use A, else B'. If every argument is None there is nothing to return, so it raises ValueError('expected at least one non-None style'). It is strict: empty call or all-None raises rather than returning a default.","triggerScenarios":"Style.pick_first(None, None); Style.pick_first(*styles) where styles is an empty or all-None list; using it to merge optional style overrides (e.g. Style.pick_first(user_style, theme_style, base_style)) when all three sources are None.","commonSituations":"Layered theming/config systems where every optional style layer is absent; passing **kwargs through several levels where the style key was never set; calling pick_first() with no arguments at all.","solutions":["Append an explicit fallback as the last argument: Style.pick_first(user_style, theme_style, Style.parse('')).","Guard the call: if any(v is not None for v in values): ... else use your default.","Rearchitect optional styles as a single Optional[StyleType] chosen with a plain 'or'-chain with a concrete default, avoiding pick_first for the always-present case."],"exampleFix":"# before\nstyle = Style.pick_first(cfg_style, theme_style)  # both None -> ValueError\n\n# after\nstyle = Style.pick_first(cfg_style, theme_style, 'none')  # last-resort default","handlingStrategy":"fallback","validationCode":"values = [v for v in (a, b, c) if v is not None]\nif not values:\n    raise ValueError('no style sources available')\nstyle = Style.pick_first(a, b, c) if values else 'none'","typeGuard":"def has_any_style(*values) -> bool:\n    return any(v is not None for v in values)","tryCatchPattern":null,"preventionTips":["Always end pick_first argument lists with a concrete fallback style.","Guard with any(v is not None ...) when all sources are optional."],"tags":["rich","style","argument-validation","valueerror","fallback"],"backgroundTag":null,"analyzedSha":"9d8f9a372cc5916fd4781fec207ced7ddac2f08f","analyzedAt":"2026-08-15T03:30:11.781Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}