Skip to content

Commit

Permalink
fix(docs): add workaround for sphinx TypeVar bug
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarbenjamin committed Nov 3, 2024
1 parent ec9f663 commit 8c5ca98
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions doc/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,21 @@ def linkcode_resolve(domain, info):

fn = os.path.relpath(fn, start=os.path.dirname(sympy.__file__))
return blobpath + fn + linespec


def resolve_type_aliases(app, env, node, contnode):
"""Resolve :class: references to our type aliases as :attr: instead."""
# A sphinx bug means that TypeVar doesn't work:
# https://github.com/sphinx-doc/sphinx/issues/10785
if (
node["refdomain"] == "py"
and node["reftype"] == "class"
and node["reftarget"] in ["sympy.utilities.decorator.T"]
):
return app.env.get_domain("py").resolve_xref(
env, node["refdoc"], app.builder, "attr", node["reftarget"], node, contnode
)


def setup(app):
app.connect("missing-reference", resolve_type_aliases)
5 changes: 3 additions & 2 deletions sympy/utilities/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from sympy.utilities.exceptions import sympy_deprecation_warning


_T = TypeVar('_T')
T = TypeVar('T')
"""A generic type"""


def threaded_factory(func, use_add):
Expand Down Expand Up @@ -180,7 +181,7 @@ def depends_on_deco(fn):
return depends_on_deco


def public(obj: _T) -> _T:
def public(obj: T) -> T:
"""
Append ``obj``'s name to global ``__all__`` variable (call site).
Expand Down

0 comments on commit 8c5ca98

Please sign in to comment.