summaryrefslogtreecommitdiff
path: root/_sphinx_13448_workaround/apps.py
blob: 76439fde4c2d0ee325d44ac32e7396d42bd0a415 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from django.apps import AppConfig
from sphinx.locale import _TranslationProxy
from sphinxcontrib.serializinghtml import jsonimpl


class FixedSphinxJSONEncoder(jsonimpl.SphinxJSONEncoder):
    def default(self, obj):
        if isinstance(obj, _TranslationProxy):
            return str(obj)
        return super().default(obj)


class SphinxBugWorkaroundConfig(AppConfig):
    """
    Add a workaround for sphinx bug https://github.com/sphinx-doc/sphinx/issues/13448
    """

    name = "_sphinx_13448_workaround"
    verbose_name = "Sphinx Bug 13448 Workaround"

    def ready(self):
        from sphinx.domains import python  # noqa: F401

        jsonimpl.SphinxJSONEncoder = FixedSphinxJSONEncoder