@@ -95,6 +95,11 @@ class C(builtins.object)
9595 | say_no(self)
9696 |\x20 \x20
9797 | ----------------------------------------------------------------------
98+ | Class methods defined here:
99+ |\x20 \x20
100+ | __class_getitem__(item) from builtins.type
101+ |\x20 \x20
102+ | ----------------------------------------------------------------------
98103 | Data descriptors defined here:
99104 |\x20 \x20
100105 | __dict__
@@ -114,6 +119,11 @@ class C(builtins.object)
114119
115120DATA
116121 __xyz__ = 'X, Y and Z'
122+ c_alias = test.pydoc_mod.C[int]
123+ list_alias1 = typing.List[int]
124+ list_alias2 = list[int]
125+ type_union1 = typing.Union[int, str]
126+ type_union2 = int | str
117127
118128VERSION
119129 1.2.3.4
@@ -141,6 +151,15 @@ class C(builtins.object)
141151 <p><tt>This is a test module for test_pydoc</tt></p>
142152<p>
143153<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
154+ <tr bgcolor="#aa55cc">
155+ <td colspan=3 valign=bottom> <br>
156+ <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
157+ \x20 \x20 \x20 \x20
158+ <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
159+ <td width="100%%"><table width="100%%" summary="list"><tr><td width="25%%" valign=top><a href="types.html">types</a><br>
160+ </td><td width="25%%" valign=top><a href="typing.html">typing</a><br>
161+ </td><td width="25%%" valign=top></td><td width="25%%" valign=top></td></tr></table></td></tr></table><p>
162+ <table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
144163<tr bgcolor="#ee77aa">
145164<td colspan=3 valign=bottom> <br>
146165<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
@@ -210,6 +229,10 @@ class C(builtins.object)
210229
211230<dl><dt><a name="C-say_no"><strong>say_no</strong></a>(self)</dt></dl>
212231
232+ <hr>
233+ Class methods defined here:<br>
234+ <dl><dt><a name="C-__class_getitem__"><strong>__class_getitem__</strong></a>(item)<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">builtins.type</a></font></font></dt></dl>
235+
213236<hr>
214237Data descriptors defined here:<br>
215238<dl><dt><strong>__dict__</strong></dt>
@@ -237,7 +260,12 @@ class C(builtins.object)
237260<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
238261\x20 \x20 \x20 \x20
239262<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
240- <td width="100%%"><strong>__xyz__</strong> = 'X, Y and Z'</td></tr></table><p>
263+ <td width="100%%"><strong>__xyz__</strong> = 'X, Y and Z'<br>
264+ <strong>c_alias</strong> = test.pydoc_mod.C[int]<br>
265+ <strong>list_alias1</strong> = typing.List[int]<br>
266+ <strong>list_alias2</strong> = list[int]<br>
267+ <strong>type_union1</strong> = typing.Union[int, str]<br>
268+ <strong>type_union2</strong> = int | str</td></tr></table><p>
241269<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
242270<tr bgcolor="#7799ee">
243271<td colspan=3 valign=bottom> <br>
@@ -1048,6 +1076,43 @@ class C: "New-style class"
10481076 expected = 'C in module %s object' % __name__
10491077 self .assertIn (expected , pydoc .render_doc (c ))
10501078
1079+ def test_generic_alias (self ):
1080+ self .assertEqual (pydoc .describe (typing .List [int ]), '_GenericAlias' )
1081+ doc = pydoc .render_doc (typing .List [int ], renderer = pydoc .plaintext )
1082+ self .assertIn ('_GenericAlias in module typing' , doc )
1083+ self .assertIn ('List = class list(object)' , doc )
1084+ self .assertIn (list .__doc__ .strip ().splitlines ()[0 ], doc )
1085+
1086+ self .assertEqual (pydoc .describe (list [int ]), 'GenericAlias' )
1087+ doc = pydoc .render_doc (list [int ], renderer = pydoc .plaintext )
1088+ self .assertIn ('GenericAlias in module builtins' , doc )
1089+ self .assertIn ('\n class list(object)' , doc )
1090+ self .assertIn (list .__doc__ .strip ().splitlines ()[0 ], doc )
1091+
1092+ def test_union_type (self ):
1093+ self .assertEqual (pydoc .describe (typing .Union [int , str ]), '_UnionGenericAlias' )
1094+ doc = pydoc .render_doc (typing .Union [int , str ], renderer = pydoc .plaintext )
1095+ self .assertIn ('_UnionGenericAlias in module typing' , doc )
1096+ self .assertIn ('Union = typing.Union' , doc )
1097+ if typing .Union .__doc__ :
1098+ self .assertIn (typing .Union .__doc__ .strip ().splitlines ()[0 ], doc )
1099+
1100+ self .assertEqual (pydoc .describe (int | str ), 'UnionType' )
1101+ doc = pydoc .render_doc (int | str , renderer = pydoc .plaintext )
1102+ self .assertIn ('UnionType in module types object' , doc )
1103+ self .assertIn ('\n class UnionType(builtins.object)' , doc )
1104+ self .assertIn (types .UnionType .__doc__ .strip ().splitlines ()[0 ], doc )
1105+
1106+ def test_special_form (self ):
1107+ self .assertEqual (pydoc .describe (typing .Any ), '_SpecialForm' )
1108+ doc = pydoc .render_doc (typing .Any , renderer = pydoc .plaintext )
1109+ self .assertIn ('_SpecialForm in module typing' , doc )
1110+ if typing .Any .__doc__ :
1111+ self .assertIn ('Any = typing.Any' , doc )
1112+ self .assertIn (typing .Any .__doc__ .strip ().splitlines ()[0 ], doc )
1113+ else :
1114+ self .assertIn ('Any = class _SpecialForm(_Final)' , doc )
1115+
10511116 def test_typing_pydoc (self ):
10521117 def foo (data : typing .List [typing .Any ],
10531118 x : int ) -> typing .Iterator [typing .Tuple [int , typing .Any ]]:
0 commit comments