@@ -95,6 +95,11 @@ class C(builtins.object)
95
95
| say_no(self)
96
96
|\x20 \x20
97
97
| ----------------------------------------------------------------------
98
+ | Class methods defined here:
99
+ |\x20 \x20
100
+ | __class_getitem__(item) from builtins.type
101
+ |\x20 \x20
102
+ | ----------------------------------------------------------------------
98
103
| Data descriptors defined here:
99
104
|\x20 \x20
100
105
| __dict__
@@ -114,6 +119,11 @@ class C(builtins.object)
114
119
115
120
DATA
116
121
__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
117
127
118
128
VERSION
119
129
1.2.3.4
@@ -135,6 +145,10 @@ class C(builtins.object)
135
145
test.pydoc_mod (version 1.2.3.4)
136
146
This is a test module for test_pydoc
137
147
148
+ Modules
149
+ types
150
+ typing
151
+
138
152
Classes
139
153
builtins.object
140
154
A
@@ -172,6 +186,8 @@ class C(builtins.object)
172
186
is_it_true(self)
173
187
Return self.get_answer()
174
188
say_no(self)
189
+ Class methods defined here:
190
+ __class_getitem__(item) from builtins.type
175
191
Data descriptors defined here:
176
192
__dict__
177
193
dictionary for instance variables (if defined)
@@ -188,6 +204,11 @@ class C(builtins.object)
188
204
189
205
Data
190
206
__xyz__ = 'X, Y and Z'
207
+ c_alias = test.pydoc_mod.C[int]
208
+ list_alias1 = typing.List[int]
209
+ list_alias2 = list[int]
210
+ type_union1 = typing.Union[int, str]
211
+ type_union2 = int | str
191
212
192
213
Author
193
214
Benjamin Peterson
@@ -1000,6 +1021,43 @@ class C: "New-style class"
1000
1021
expected = 'C in module %s object' % __name__
1001
1022
self .assertIn (expected , pydoc .render_doc (c ))
1002
1023
1024
+ def test_generic_alias (self ):
1025
+ self .assertEqual (pydoc .describe (typing .List [int ]), '_GenericAlias' )
1026
+ doc = pydoc .render_doc (typing .List [int ], renderer = pydoc .plaintext )
1027
+ self .assertIn ('_GenericAlias in module typing' , doc )
1028
+ self .assertIn ('List = class list(object)' , doc )
1029
+ self .assertIn (list .__doc__ .strip ().splitlines ()[0 ], doc )
1030
+
1031
+ self .assertEqual (pydoc .describe (list [int ]), 'GenericAlias' )
1032
+ doc = pydoc .render_doc (list [int ], renderer = pydoc .plaintext )
1033
+ self .assertIn ('GenericAlias in module builtins' , doc )
1034
+ self .assertIn ('\n class list(object)' , doc )
1035
+ self .assertIn (list .__doc__ .strip ().splitlines ()[0 ], doc )
1036
+
1037
+ def test_union_type (self ):
1038
+ self .assertEqual (pydoc .describe (typing .Union [int , str ]), '_UnionGenericAlias' )
1039
+ doc = pydoc .render_doc (typing .Union [int , str ], renderer = pydoc .plaintext )
1040
+ self .assertIn ('_UnionGenericAlias in module typing' , doc )
1041
+ self .assertIn ('Union = typing.Union' , doc )
1042
+ if typing .Union .__doc__ :
1043
+ self .assertIn (typing .Union .__doc__ .strip ().splitlines ()[0 ], doc )
1044
+
1045
+ self .assertEqual (pydoc .describe (int | str ), 'UnionType' )
1046
+ doc = pydoc .render_doc (int | str , renderer = pydoc .plaintext )
1047
+ self .assertIn ('UnionType in module types object' , doc )
1048
+ self .assertIn ('\n class UnionType(builtins.object)' , doc )
1049
+ self .assertIn (types .UnionType .__doc__ .strip ().splitlines ()[0 ], doc )
1050
+
1051
+ def test_special_form (self ):
1052
+ self .assertEqual (pydoc .describe (typing .Any ), '_SpecialForm' )
1053
+ doc = pydoc .render_doc (typing .Any , renderer = pydoc .plaintext )
1054
+ self .assertIn ('_SpecialForm in module typing' , doc )
1055
+ if typing .Any .__doc__ :
1056
+ self .assertIn ('Any = typing.Any' , doc )
1057
+ self .assertIn (typing .Any .__doc__ .strip ().splitlines ()[0 ], doc )
1058
+ else :
1059
+ self .assertIn ('Any = class _SpecialForm(_Final)' , doc )
1060
+
1003
1061
def test_typing_pydoc (self ):
1004
1062
def foo (data : typing .List [typing .Any ],
1005
1063
x : int ) -> typing .Iterator [typing .Tuple [int , typing .Any ]]:
0 commit comments