{"record":{"id":"23e9153a6309a5d0","repo":"subframe7536/maple-font","slug":"g-type-g-is-invalid-for-gly","errorCode":null,"errorMessage":"{g}({type(g)}) is invalid for __gly","messagePattern":"(.+?)\\((.+?)\\) is invalid for __gly","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/py/feature/ast.py","lineNumber":247,"sourceCode":"__PUNCTUATION_CN_MAP = {\n    \"“\": \"quotedblleft\",\n    \"”\": \"quotedblright\",\n    \"‘\": \"quoteleft\",\n    \"’\": \"quoteright\",\n    \"…\": \"ellipsis\",\n    \"—\": \"emdash\",\n}\n\n\ndef __gly(g: str | Clazz | Sequence[str | Clazz] | None) -> str:\n    if not g:\n        return \"\"\n    if isinstance(g, list):\n        return \" \".join([__gly(_) for _ in g])\n    if isinstance(g, Clazz):\n        return g.use()\n    if not isinstance(g, str):\n        raise TypeError(f\"{g}({type(g)}) is invalid for __gly\")\n    if g in __PUNCTUATION_MAP:\n        return __PUNCTUATION_MAP[g]\n    if g in __PUNCTUATION_CN_MAP:\n        return __PUNCTUATION_CN_MAP[g]\n    return g\n\n\ndef __prefix(data: str | Clazz | Sequence[str | Clazz] | None) -> str:\n    if data:\n        return __gly(data) + \" \"\n    return \"\"\n\n\ndef __suffix(data: str | Clazz | Sequence[str | Clazz] | None) -> str:\n    if data:\n        return \" \" + __gly(data)\n    return \"\"\n","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/subframe7536/maple-font/blob/c08fda97fef73d68c1755219852150770f6e6578/source/py/feature/ast.py#L229-L265","documentation":"__gly is the internal glyph serializer that converts any glyph spec (str, list of specs, or Clazz) into FEA text. When it receives a value of any other type (int, None, dict, glyph object, etc.) it raises TypeError naming the value and its type. Since __gly is recursive (lists call __gly per element), a single bad element inside a nested list triggers it.","triggerScenarios":"Passing a non-str/non-Clazz value into ast.gly(), ast.subst()/subst_liga() source or target positions, or nesting such a value inside a list passed to those APIs — e.g. None from a failed lookup, an int codepoint, or a parsed glyph object instead of its name string.","commonSituations":"Reading glyph names from JSON/YAML where values arrive as numbers or null; building glyph lists programmatically and appending None from an earlier failed operation; passing custom glyph objects instead of str.","solutions":["Convert the offending value to a str glyph name before passing it (e.g. chr(cp) for codepoints).","Replace None entries with a valid glyph name or filter them out of lists.","Wrap glyph objects with .name (or their string form) if you have custom glyph types.","If you need new supported types, extend __gly in source/py/feature/ast.py rather than passing raw objects."],"exampleFix":"// before\nast.subst(None, 65, None, 'space')  # 65 is an int\n// after\nast.subst(None, chr(65), None, 'space')  # 'A'","handlingStrategy":"type-guard","validationCode":"def validate_glyph(g):\n    if g is None:\n        raise ValueError('glyph is None — upstream lookup failed')\n    if not isinstance(g, (str, ast.Clazz, list)):\n        raise TypeError(f'{g!r} ({type(g).__name__}) must be str, Clazz, or list')\n    if isinstance(g, list):\n        for x in g: validate_glyph(x)\n\nvalidate_glyph(my_glyph)\nresult = ast.gly(my_glyph)","typeGuard":"def is_glyph_spec(g) -> bool:\n    if isinstance(g, ast.Clazz) or isinstance(g, str):\n        return True\n    return isinstance(g, list) and all(is_glyph_spec(x) for x in g)","tryCatchPattern":"try:\n    seq = ast.gly(glyph_spec)\nexcept TypeError as e:\n    if 'is invalid for __gly' in str(e):\n        glyph_spec = str(glyph_spec)  # or chr(codepoint) / glyph.name\n        seq = ast.gly(glyph_spec)\n    else:\n        raise","preventionTips":["Convert codepoints to glyph-name strings with chr() before passing.","Check for None entries after any dynamic glyph lookup — they propagate into __gly.","Validate config-loaded glyph data (JSON numbers/nulls) at parse time."],"tags":["python","typeerror","glyph","invalid-argument","ast"],"backgroundTag":"invalid-glyph-type","analyzedSha":"c08fda97fef73d68c1755219852150770f6e6578","analyzedAt":"2026-08-28T22:07:29.503Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}