Skip to content

Commit

Permalink
Fix sphinx.util.inspect_evaluate_forwardref for Python 3.12.4 (#12317)
Browse files Browse the repository at this point in the history
Python has recently [1] changed the signature of `_evaluate` for forward references
because of type parameters. The change affects 3.13, and was backported to 3.12.4.

[1]: python/cpython#118104
  • Loading branch information
picnixz authored Apr 23, 2024
1 parent 85fd284 commit b5f3ef9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sphinx/util/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,13 @@ def _evaluate_forwardref(
localns: dict[str, Any] | None,
) -> Any:
"""Evaluate a forward reference."""
if sys.version_info >= (3, 12, 4):
# ``type_params`` were added in 3.13 and the signature of _evaluate()
# is not backward-compatible (it was backported to 3.12.4, so anything
# before 3.12.4 still has the old signature).
#
# See: https://github.com/python/cpython/pull/118104.
return ref._evaluate(globalns, localns, {}, recursive_guard=frozenset()) # type: ignore[arg-type, misc]
return ref._evaluate(globalns, localns, frozenset())


Expand Down

0 comments on commit b5f3ef9

Please sign in to comment.