{"record":{"id":"6eae9b9e4447da69","repo":"PaddlePaddle/PaddleOCR","slug":"not-found","errorCode":null,"errorMessage":"{} not found","messagePattern":"(.+?) not found","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"ppstructure/table/tablepyxl/style.py","lineNumber":143,"sourceCode":"    return known_styles[style_and_format_string]\n\n\nclass StyleDict(dict):\n    \"\"\"\n    It's like a dictionary, but it looks for items in the parent dictionary\n    \"\"\"\n\n    def __init__(self, *args, **kwargs):\n        self.parent = kwargs.pop(\"parent\", None)\n        super(StyleDict, self).__init__(*args, **kwargs)\n\n    def __getitem__(self, item):\n        if item in self:\n            return super(StyleDict, self).__getitem__(item)\n        elif self.parent:\n            return self.parent[item]\n        else:\n            raise KeyError(\"{} not found\".format(item))\n\n    def __hash__(self):\n        return hash(tuple([(k, self.get(k)) for k in self._keys()]))\n\n    # Yielding the keys avoids creating unnecessary data structures\n    # and happily works with both python2 and python3 where the\n    # .keys() method is a dictionary_view in python3 and a list in python2.\n    def _keys(self):\n        yielded = set()\n        for k in self.keys():\n            yielded.add(k)\n            yield k\n        if self.parent:\n            for k in self.parent._keys():\n                if k not in yielded:\n                    yielded.add(k)\n                    yield k\n","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppstructure/table/tablepyxl/style.py#L125-L161","documentation":"StyleDict is a dict subclass with parent-chain lookup used by the tablepyxl (HTML-table-to-xlsx) renderer: CSS-like style keys not present locally are fetched from the parent StyleDict, mimicking CSS inheritance. KeyError is raised only when the key exists neither in the dict nor anywhere up the parent chain. It means tablepyxl was asked for a style attribute (font, border, alignment property) that was never set on the cell or its ancestors.","triggerScenarios":"Calling style_dict['border'] (or similar key) on a StyleDict built from a <td> whose style chain has no such key — typically when parsing HTML without inline styles or when internal code requests an optional attribute directly with [] instead of .get().","commonSituations":"Feeding HTML tables that use CSS classes/stylesheets instead of inline style attributes (tablepyxl only reads inline styles); a parent style chain that was never initialized; custom forks querying style keys that upstream code never populates.","solutions":["Use .get(key, default) instead of [key] when reading optional style attributes from StyleDict","Provide inline style attributes (style=\"border: ...\") on the table HTML you feed to tablepyxl","Seed a root StyleDict with defaults for the keys your code reads so every lookup resolves via the parent chain"],"exampleFix":"# before\nborder = cell_style['border-top-width']  # KeyError: ... not found\n\n# after\nborder = cell_style.get('border-top-width', '1pt')","handlingStrategy":"type-guard","validationCode":"value = style_dict.get('border-top-width')\nif value is None:\n    value = '1pt'  # document your default instead of relying on KeyError","typeGuard":"def has_style_key(style_dict, key: str) -> bool:\n    d = style_dict\n    while d is not None:\n        if key in d:\n            return True\n        d = getattr(d, 'parent', None)\n    return False","tryCatchPattern":"try:\n    val = style_dict[key]\nexcept KeyError:\n    val = DEFAULT_STYLE.get(key)  # never let StyleDict misses crash the render","preventionTips":["Read optional style attributes with .get(key, default), reserving [] for required keys","Root every StyleDict chain in a defaults dict so lookups always terminate successfully"],"tags":["xlsx","css-inheritance","keyerror","tablepyxl"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}