File tree 2 files changed +32
-5
lines changed
2 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -206,6 +206,11 @@ def params_documented_elsewhere(self):
206
206
class SphinxDocstring (Docstring ):
207
207
re_type = r"[\w\.]+"
208
208
209
+ re_simple_container_type = r"""
210
+ {type} # a container type
211
+ [\(\[] [^\n\s]+ [\)\]] # with the contents of the container
212
+ """ .format (type = re_type )
213
+
209
214
re_xref = r"""
210
215
(?::\w+:)? # optional tag
211
216
`{0}` # what to reference
@@ -221,14 +226,14 @@ class SphinxDocstring(Docstring):
221
226
\s+ # whitespace
222
227
223
228
(?: # optional type declaration
224
- ({type})
229
+ ({type}|{container_type} )
225
230
\s+
226
231
)?
227
232
228
233
(\w+) # Parameter name
229
234
\s* # whitespace
230
235
: # final colon
231
- """ .format (type = re_type )
236
+ """ .format (type = re_type , container_type = re_simple_container_type )
232
237
re_param_in_docstring = re .compile (re_param_raw , re .X | re .S )
233
238
234
239
re_type_raw = r"""
Original file line number Diff line number Diff line change @@ -1349,11 +1349,17 @@ def my_func(named_arg, **kwargs):
1349
1349
with self .assertNoMessages ():
1350
1350
self .checker .visit_functiondef (node )
1351
1351
1352
- COMPLEX_TYPES = [
1353
- 'int or str' ,
1352
+ CONTAINER_TYPES = [
1353
+ 'dict(str,str)' ,
1354
+ 'dict[str,str]' ,
1355
+ 'tuple(int)' ,
1356
+ 'list[tokenize.TokenInfo]' ,
1357
+ ]
1358
+
1359
+ COMPLEX_TYPES = CONTAINER_TYPES + [
1354
1360
'dict(str, str)' ,
1355
1361
'dict[str, str]' ,
1356
- 'tuple( int) ' ,
1362
+ 'int or str ' ,
1357
1363
'tuple(int or str)' ,
1358
1364
'tuple(int) or list(int)' ,
1359
1365
'tuple(int or str) or list(int or str)' ,
@@ -1414,6 +1420,22 @@ def my_func(named_arg):
1414
1420
with self .assertNoMessages ():
1415
1421
self .checker .visit_functiondef (node )
1416
1422
1423
+ @pytest .mark .parametrize ('container_type' , CONTAINER_TYPES )
1424
+ def test_finds_compact_container_types_sphinx (self , container_type ):
1425
+ node = astroid .extract_node ('''
1426
+ def my_func(named_arg):
1427
+ """The docstring
1428
+
1429
+ :param {0} named_arg: Returned
1430
+
1431
+ :returns: named_arg
1432
+ :rtype: {0}
1433
+ """
1434
+ return named_arg
1435
+ ''' .format (container_type ))
1436
+ with self .assertNoMessages ():
1437
+ self .checker .visit_functiondef (node )
1438
+
1417
1439
def test_ignores_optional_specifier_numpy (self ):
1418
1440
node = astroid .extract_node ('''
1419
1441
def do_something(param, param2='all'):
You can’t perform that action at this time.
0 commit comments