8000 gh-128184: Fix display of signatures with ForwardRefs by JelleZijlstra · Pull Request #130815 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixes and additions
  • Loading branch information
JelleZijlstra committed Mar 3, 2025
commit e36c0e068999ec7b92067982f1db7e0ba33bb550
9 changes: 8 additions & 1 deletion Lib/test/test_dataclasses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2344,6 +2344,13 @@ class C:

self.assertDocStrEqual(C.__doc__, "C(x:collections.deque=<factory>)")

def test_docstring_undefined_name(self):
@dataclass
class C:
x: undef

self.assertDocStrEqual(C.__doc__, "C(x:undef)")

def test_docstring_with_unsolvable_forward_ref_in_init(self):
# See: https://github.com/python/cpython/issues/128184
ns = {}
Expand All @@ -2360,7 +2367,7 @@ def __init__(self, x: X, num: int) -> None: ...
ns,
)

self.assertDocStrEqual(ns['C'].__doc__, "C(x:'X',num:'int')")
self.assertDocStrEqual(ns['C'].__doc__, "C(x:X,num:int)")

def test_docstring_with_no_signature(self):
# See https://github.com/python/cpython/issues/103449
Expand Down
3 changes: 1 addition & 2 deletions Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from Lib import annotationlib
from annotationlib import Format, ForwardRef
import asyncio
import builtins
Expand Down Expand Up @@ -4594,7 +4593,7 @@ def foo(a: list[str]) -> Tuple[str, float]:

def foo(x: undef):
pass
sig = inspect.signature(foo, annotation_format=annotationlib.Format.FORWARDREF)
sig = inspect.signature(foo, annotation_format=Format.FORWARDREF)
self.assertEqual(str(sig), '(x: undef)')

def test_signature_str_positional_only(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Fixes :exc:`NameError` when using :func:`dataclasses.dataclass` on classes
with unresolvable forward references.
Improve display of :class:`annotationlib.ForwardRef` object
within :class:`inspect.Signature` representations.
This also fixes a :exc:`NameError` that was raised when using
:func:`dataclasses.dataclass` on classes with unresolvable forward references.
Loading
0