mirror of
https://github.com/python/cpython.git
synced 2025-10-14 02:43:49 +00:00
bpo-40296: Fix supporting generic aliases in pydoc (GH-30253)
This commit is contained in:
parent
a0db11b10f
commit
cd44afc573
4 changed files with 84 additions and 9 deletions
|
@ -95,6 +95,11 @@ CLASSES
|
|||
| say_no(self)
|
||||
|\x20\x20
|
||||
| ----------------------------------------------------------------------
|
||||
| Class methods defined here:
|
||||
|\x20\x20
|
||||
| __class_getitem__(item) from builtins.type
|
||||
|\x20\x20
|
||||
| ----------------------------------------------------------------------
|
||||
| Data descriptors defined here:
|
||||
|\x20\x20
|
||||
| __dict__
|
||||
|
@ -114,6 +119,11 @@ FUNCTIONS
|
|||
|
||||
DATA
|
||||
__xyz__ = 'X, Y and Z'
|
||||
c_alias = test.pydoc_mod.C[int]
|
||||
list_alias1 = typing.List[int]
|
||||
list_alias2 = list[int]
|
||||
type_union1 = typing.Union[int, str]
|
||||
type_union2 = int | str
|
||||
|
||||
VERSION
|
||||
1.2.3.4
|
||||
|
@ -135,6 +145,10 @@ html2text_of_expected = """
|
|||
test.pydoc_mod (version 1.2.3.4)
|
||||
This is a test module for test_pydoc
|
||||
|
||||
Modules
|
||||
types
|
||||
typing
|
||||
|
||||
Classes
|
||||
builtins.object
|
||||
A
|
||||
|
@ -172,6 +186,8 @@ class C(builtins.object)
|
|||
is_it_true(self)
|
||||
Return self.get_answer()
|
||||
say_no(self)
|
||||
Class methods defined here:
|
||||
__class_getitem__(item) from builtins.type
|
||||
Data descriptors defined here:
|
||||
__dict__
|
||||
dictionary for instance variables (if defined)
|
||||
|
@ -188,6 +204,11 @@ Functions
|
|||
|
||||
Data
|
||||
__xyz__ = 'X, Y and Z'
|
||||
c_alias = test.pydoc_mod.C[int]
|
||||
list_alias1 = typing.List[int]
|
||||
list_alias2 = list[int]
|
||||
type_union1 = typing.Union[int, str]
|
||||
type_union2 = int | str
|
||||
|
||||
Author
|
||||
Benjamin Peterson
|
||||
|
@ -1000,6 +1021,43 @@ class TestDescriptions(unittest.TestCase):
|
|||
expected = 'C in module %s object' % __name__
|
||||
self.assertIn(expected, pydoc.render_doc(c))
|
||||
|
||||
def test_generic_alias(self):
|
||||
self.assertEqual(pydoc.describe(typing.List[int]), '_GenericAlias')
|
||||
doc = pydoc.render_doc(typing.List[int], renderer=pydoc.plaintext)
|
||||
self.assertIn('_GenericAlias in module typing', doc)
|
||||
self.assertIn('List = class list(object)', doc)
|
||||
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
|
||||
|
||||
self.assertEqual(pydoc.describe(list[int]), 'GenericAlias')
|
||||
doc = pydoc.render_doc(list[int], renderer=pydoc.plaintext)
|
||||
self.assertIn('GenericAlias in module builtins', doc)
|
||||
self.assertIn('\nclass list(object)', doc)
|
||||
self.assertIn(list.__doc__.strip().splitlines()[0], doc)
|
||||
|
||||
def test_union_type(self):
|
||||
self.assertEqual(pydoc.describe(typing.Union[int, str]), '_UnionGenericAlias')
|
||||
doc = pydoc.render_doc(typing.Union[int, str], renderer=pydoc.plaintext)
|
||||
self.assertIn('_UnionGenericAlias in module typing', doc)
|
||||
self.assertIn('Union = typing.Union', doc)
|
||||
if typing.Union.__doc__:
|
||||
self.assertIn(typing.Union.__doc__.strip().splitlines()[0], doc)
|
||||
|
||||
self.assertEqual(pydoc.describe(int | str), 'UnionType')
|
||||
doc = pydoc.render_doc(int | str, renderer=pydoc.plaintext)
|
||||
self.assertIn('UnionType in module types object', doc)
|
||||
self.assertIn('\nclass UnionType(builtins.object)', doc)
|
||||
self.assertIn(types.UnionType.__doc__.strip().splitlines()[0], doc)
|
||||
|
||||
def test_special_form(self):
|
||||
self.assertEqual(pydoc.describe(typing.Any), '_SpecialForm')
|
||||
doc = pydoc.render_doc(typing.Any, renderer=pydoc.plaintext)
|
||||
self.assertIn('_SpecialForm in module typing', doc)
|
||||
if typing.Any.__doc__:
|
||||
self.assertIn('Any = typing.Any', doc)
|
||||
self.assertIn(typing.Any.__doc__.strip().splitlines()[0], doc)
|
||||
else:
|
||||
self.assertIn('Any = class _SpecialForm(_Final)', doc)
|
||||
|
||||
def test_typing_pydoc(self):
|
||||
def foo(data: typing.List[typing.Any],
|
||||
x: int) -> typing.Iterator[typing.Tuple[int, typing.Any]]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue