Skip to content

Commit b5f3ef9

Browse files
authored
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]: python/cpython#118104
1 parent 85fd284 commit b5f3ef9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

sphinx/util/inspect.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,13 @@ def _evaluate_forwardref(
718718
localns: dict[str, Any] | None,
719719
) -> Any:
720720
"""Evaluate a forward reference."""
721+
if sys.version_info >= (3, 12, 4):
722+
# ``type_params`` were added in 3.13 and the signature of _evaluate()
723+
# is not backward-compatible (it was backported to 3.12.4, so anything
724+
# before 3.12.4 still has the old signature).
725+
#
726+
# See: https://github.com/python/cpython/pull/118104.
727+
return ref._evaluate(globalns, localns, {}, recursive_guard=frozenset()) # type: ignore[arg-type, misc]
721728
return ref._evaluate(globalns, localns, frozenset())
722729

723730

0 commit comments

Comments
 (0)