gh-128184: Fix display of signatures with ForwardRefs (#130815)

Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
Jelle Zijlstra 2025-03-04 06:58:37 -08:00 committed by GitHub
parent 80e6d3ec49
commit 1d251b8339
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 46 additions and 2 deletions

View file

@ -1163,7 +1163,10 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen,
try:
# In some cases fetching a signature is not possible.
# But, we surely should not fail in this case.
text_sig = str(inspect.signature(cls)).replace(' -> None', '')
text_sig = str(inspect.signature(
cls,
annotation_format=annotationlib.Format.FORWARDREF,
)).replace(' -> None', '')
except (TypeError, ValueError):
text_sig = ''
cls.__doc__ = (cls.__name__ + text_sig)