Skip to content

Commit ff45b2d

Browse files
AWhetterPCManticore
authored andcommitted
Fixed false positive for compact argument docs with container types
1 parent e100ce4 commit ff45b2d

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

pylint/extensions/_check_docs_utils.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ def params_documented_elsewhere(self):
206206
class SphinxDocstring(Docstring):
207207
re_type = r"[\w\.]+"
208208

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+
209214
re_xref = r"""
210215
(?::\w+:)? # optional tag
211216
`{0}` # what to reference
@@ -221,14 +226,14 @@ class SphinxDocstring(Docstring):
221226
\s+ # whitespace
222227
223228
(?: # optional type declaration
224-
({type})
229+
({type}|{container_type})
225230
\s+
226231
)?
227232
228233
(\w+) # Parameter name
229234
\s* # whitespace
230235
: # final colon
231-
""".format(type=re_type)
236+
""".format(type=re_type, container_type=re_simple_container_type)
232237
re_param_in_docstring = re.compile(re_param_raw, re.X | re.S)
233238

234239
re_type_raw = r"""

pylint/test/extensions/test_check_docs.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -1349,11 +1349,17 @@ def my_func(named_arg, **kwargs):
13491349
with self.assertNoMessages():
13501350
self.checker.visit_functiondef(node)
13511351

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 + [
13541360
'dict(str, str)',
13551361
'dict[str, str]',
1356-
'tuple(int)',
1362+
'int or str',
13571363
'tuple(int or str)',
13581364
'tuple(int) or list(int)',
13591365
'tuple(int or str) or list(int or str)',
@@ -1414,6 +1420,22 @@ def my_func(named_arg):
14141420
with self.assertNoMessages():
14151421
self.checker.visit_functiondef(node)
14161422

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+
14171439
def test_ignores_optional_specifier_numpy(self):
14181440
node = astroid.extract_node('''
14191441
def do_something(param, param2='all'):

0 commit comments

Comments
 (0)