Skip to content
Snippets Groups Projects
Commit ff45b2d0 authored by Ashley Whetter's avatar Ashley Whetter Committed by Claudiu Popa
Browse files

Fixed false positive for compact argument docs with container types

parent e100ce48
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -206,6 +206,11 @@ class Docstring(object):
class SphinxDocstring(Docstring):
re_type = r"[\w\.]+"
 
re_simple_container_type = r"""
{type} # a container type
[\(\[] [^\n\s]+ [\)\]] # with the contents of the container
""".format(type=re_type)
re_xref = r"""
(?::\w+:)? # optional tag
`{0}` # what to reference
Loading
Loading
@@ -221,14 +226,14 @@ class SphinxDocstring(Docstring):
\s+ # whitespace
 
(?: # optional type declaration
({type})
({type}|{container_type})
\s+
)?
 
(\w+) # Parameter name
\s* # whitespace
: # final colon
""".format(type=re_type)
""".format(type=re_type, container_type=re_simple_container_type)
re_param_in_docstring = re.compile(re_param_raw, re.X | re.S)
 
re_type_raw = r"""
Loading
Loading
Loading
Loading
@@ -1349,11 +1349,17 @@ class TestParamDocChecker(CheckerTestCase):
with self.assertNoMessages():
self.checker.visit_functiondef(node)
 
COMPLEX_TYPES = [
'int or str',
CONTAINER_TYPES = [
'dict(str,str)',
'dict[str,str]',
'tuple(int)',
'list[tokenize.TokenInfo]',
]
COMPLEX_TYPES = CONTAINER_TYPES + [
'dict(str, str)',
'dict[str, str]',
'tuple(int)',
'int or str',
'tuple(int or str)',
'tuple(int) or list(int)',
'tuple(int or str) or list(int or str)',
Loading
Loading
@@ -1414,6 +1420,22 @@ class TestParamDocChecker(CheckerTestCase):
with self.assertNoMessages():
self.checker.visit_functiondef(node)
 
@pytest.mark.parametrize('container_type', CONTAINER_TYPES)
def test_finds_compact_container_types_sphinx(self, container_type):
node = astroid.extract_node('''
def my_func(named_arg):
"""The docstring
:param {0} named_arg: Returned
:returns: named_arg
:rtype: {0}
"""
return named_arg
'''.format(container_type))
with self.assertNoMessages():
self.checker.visit_functiondef(node)
def test_ignores_optional_specifier_numpy(self):
node = astroid.extract_node('''
def do_something(param, param2='all'):
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment