The generated docs converts these to decimal values as so:
\n
\nI'd like to maintain the source code representation. Is this possible?
\nAdditionally I'd love the table to also say what the value is too.
","upvoteCount":2,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"OK so, it won't be possible to fix this while we keep using ast, but I can imagine a few solutions:
import griffe\n\nclass ToHex(griffe.Extension):\n def __init__(self, objects: list[str]) -> None:\n self._objects = set(objects)\n\n def on_attribute(self, *, attr: griffe.Attribute, **kwargs) -> None:\n if attr.path in self._objects:\n if isinstance(attr.value, griffe.ExprConstant): # just to be sure\n attr.value.value = hex(int(attr.value.value))Maybe make it accept paths to enums instead of enum values:
\nimport griffe\n\nclass ToHex(griffe.Extension):\n def __init__(self, objects: list[str]) -> None:\n self._objects = set(objects)\n\n def on_class_members(self, *, cls: griffe.Class, **kwargs) -> None:\n if cls.path in self._objects:\n for attr in cls.attributes.values():\n if isinstance(attr.value, griffe.ExprConstant): # just to be sure\n attr.value.value = hex(int(attr.value.value))In mkdocs.yml:
\nplugins:\n- mkdocstrings:\n handlers:\n python:\n options:\n extensions:\n - scripts/griffe_extensions.py: # or wherever you wrote your extension\n objects:\n - path.to.Enum1\n - path.to.Enum2-
Beta Was this translation helpful? Give feedback.
-
|
Oh, interesting, |
Beta Was this translation helpful? Give feedback.
OK so, it won't be possible to fix this while we keep using
ast, but I can imagine a few solutions: