Fix sphinx.util.inspect_evaluate_forwardref for Python 3.12.4 (#12317)

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]: https://github.com/python/cpython/pull/118104
This commit is contained in:
Bénédikt Tran
2024-04-23 20:25:34 +02:00
committed by GitHub
parent 85fd284476
commit b5f3ef987a

View File

@@ -718,6 +718,13 @@ def _evaluate_forwardref(
localns: dict[str, Any] | None, localns: dict[str, Any] | None,
) -> Any: ) -> Any:
"""Evaluate a forward reference.""" """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()) return ref._evaluate(globalns, localns, frozenset())