mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-128184: Fix display of signatures with ForwardRefs (#130815)
Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
parent
80e6d3ec49
commit
1d251b8339
5 changed files with 46 additions and 2 deletions
|
@ -12,6 +12,7 @@ import builtins
|
|||
import types
|
||||
import weakref
|
||||
import traceback
|
||||
import textwrap
|
||||
import unittest
|
||||
from unittest.mock import Mock
|
||||
from typing import ClassVar, Any, List, Union, Tuple, Dict, Generic, TypeVar, Optional, Protocol, DefaultDict
|
||||
|
@ -2343,6 +2344,31 @@ class TestDocString(unittest.TestCase):
|
|||
|
||||
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 = {}
|
||||
exec(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class C:
|
||||
def __init__(self, x: X, num: int) -> None: ...
|
||||
""",
|
||||
),
|
||||
ns,
|
||||
)
|
||||
|
||||
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
|
||||
class Meta(type):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue