Skip to content

Commit

Permalink
Merge branch 'undefined-variable' of https://github.com/DanielNoord/p…
Browse files Browse the repository at this point in the history
…ylint into undefined-variable
  • Loading branch information
DanielNoord committed Oct 18, 2021
2 parents 63e34c0 + 8e6cd18 commit f7333e2
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 19 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ Release date: TBA

Closes #4774

* ``mising-param-doc`` now correctly parses asterisks for variable length and
keyword parameters

Closes #3733

* Update ``literal-comparison``` checker to ignore tuple literals

Closes #3031
Expand Down
5 changes: 5 additions & 0 deletions doc/whatsnew/2.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,8 @@ Other Changes
or default values in first-level methods

Closes #3771

* ``mising-param-doc`` now correctly parses asterisks for variable length and
keyword parameters

Closes #3733
6 changes: 3 additions & 3 deletions pylint/extensions/_check_docs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class SphinxDocstring(Docstring):
\s+
)?
(\w+) # Parameter name
(\*{{0,2}}\w+) # Parameter name with potential asterisks
\s* # whitespace
: # final colon
"""
Expand Down Expand Up @@ -472,7 +472,7 @@ class GoogleDocstring(Docstring):

re_param_line = re.compile(
fr"""
\s* \*{{0,2}}(\w+) # identifier potentially with asterisks
\s* (\*{{0,2}}\w+) # identifier potentially with asterisks
\s* ( [(]
{re_multiple_type}
(?:,\s+optional)?
Expand Down Expand Up @@ -731,7 +731,7 @@ class NumpyDocstring(GoogleDocstring):

re_param_line = re.compile(
fr"""
\s* (\w+) # identifier
\s* (\*{{0,2}}\w+) # identifier with potential asterisks
\s* :
\s* (?:({GoogleDocstring.re_multiple_type})(?:,\s+optional)?)? # optional type declaration
\s* (.*) # optional description
Expand Down
8 changes: 4 additions & 4 deletions pylint/extensions/docparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,11 +536,11 @@ class constructor.
}

if arguments_node.vararg is not None:
expected_argument_names.add(arguments_node.vararg)
not_needed_type_in_docstring.add(arguments_node.vararg)
expected_argument_names.add(f"*{arguments_node.vararg}")
not_needed_type_in_docstring.add(f"*{arguments_node.vararg}")
if arguments_node.kwarg is not None:
expected_argument_names.add(arguments_node.kwarg)
not_needed_type_in_docstring.add(arguments_node.kwarg)
expected_argument_names.add(f"**{arguments_node.kwarg}")
not_needed_type_in_docstring.add(f"**{arguments_node.kwarg}")
params_with_doc, params_with_type = doc.match_param_docs()
# Tolerate no parameter documentation at all.
if not params_with_doc and not params_with_type and accept_no_param_doc:
Expand Down
2 changes: 1 addition & 1 deletion pylint/reporters/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def colorize_ansi(
:param style: the message's style elements, this will be deprecated
:param kwargs: used to accept `color` parameter while it is being deprecated
:param **kwargs: used to accept `color` parameter while it is being deprecated
:return: the ansi escaped string
"""
Expand Down
22 changes: 11 additions & 11 deletions tests/extensions/test_check_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ def my_func(named_arg, *args):
'''
)
with self.assertAddsMessages(
MessageTest(msg_id="missing-param-doc", node=node, args=("args",))
MessageTest(msg_id="missing-param-doc", node=node, args=("*args",))
):
self.checker.visit_functiondef(node)

Expand All @@ -1161,7 +1161,7 @@ def my_func(named_arg, **kwargs):
'''
)
with self.assertAddsMessages(
MessageTest(msg_id="missing-param-doc", node=node, args=("kwargs",))
MessageTest(msg_id="missing-param-doc", node=node, args=("**kwargs",))
):
self.checker.visit_functiondef(node)

Expand All @@ -1182,7 +1182,7 @@ def my_func(named_arg, *args):
'''
)
with self.assertAddsMessages(
MessageTest(msg_id="missing-param-doc", node=node, args=("args",))
MessageTest(msg_id="missing-param-doc", node=node, args=("*args",))
):
self.checker.visit_functiondef(node)

Expand All @@ -1203,7 +1203,7 @@ def my_func(named_arg, **kwargs):
'''
)
with self.assertAddsMessages(
MessageTest(msg_id="missing-param-doc", node=node, args=("kwargs",))
MessageTest(msg_id="missing-param-doc", node=node, args=("**kwargs",))
):
self.checker.visit_functiondef(node)

Expand All @@ -1228,7 +1228,7 @@ def my_func(named_arg, *args):
'''
)
with self.assertAddsMessages(
MessageTest(msg_id="missing-param-doc", node=node, args=("args",))
MessageTest(msg_id="missing-param-doc", node=node, args=("*args",))
):
self.checker.visit_functiondef(node)

Expand All @@ -1253,7 +1253,7 @@ def my_func(named_arg, **kwargs):
'''
)
with self.assertAddsMessages(
MessageTest(msg_id="missing-param-doc", node=node, args=("kwargs",))
MessageTest(msg_id="missing-param-doc", node=node, args=("**kwargs",))
):
self.checker.visit_functiondef(node)

Expand All @@ -1265,7 +1265,7 @@ def my_func(named_arg, *args):
:param named_arg: Returned
:type named_arg: object
:param args: Optional arguments
:param *args: Optional arguments
:returns: Maybe named_arg
:rtype: object or None
"""
Expand All @@ -1284,7 +1284,7 @@ def my_func(named_arg, **kwargs):
:param named_arg: Returned
:type named_arg: object
:param kwargs: Keyword arguments
:param **kwargs: Keyword arguments
:returns: Maybe named_arg
:rtype: object or None
"""
Expand Down Expand Up @@ -1345,7 +1345,7 @@ def my_func(named_arg, *args):
----
named_arg : object
Returned
args :
*args :
Optional Arguments
Returns
Expand Down Expand Up @@ -1390,7 +1390,7 @@ def my_func(named_arg, *args):
----
named_arg : `example.value`
Returned
args :
*args :
Optional Arguments
Returns
Expand All @@ -1415,7 +1415,7 @@ def my_func(named_arg, **kwargs):
----
named_arg : object
Returned
kwargs :
**kwargs :
Keyword arguments
Returns
Expand Down
36 changes: 36 additions & 0 deletions tests/functional/m/missing/missing_param_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,39 @@ def foobar12(arg1, arg2, arg3): #[missing-param-doc, missing-type-doc]
arg3
"""
print(arg1, arg2, arg3)

def foobar13(arg1, *args, arg3=";"):
"""Description of the function
Parameters
----------
arg1 : str
Path to the input.
*args :
Relevant parameters.
arg3 : str, optional
File separator.
"""
print(arg1, args, arg3)

def foobar14(arg1, *args):
"""Description of the function
Parameters
----------
arg1 : str
Path to the input.
*args :
Relevant parameters.
"""
print(arg1, args)

def foobar15(*args):
"""Description of the function
Parameters
----------
*args :
Relevant parameters.
"""
print(args)

0 comments on commit f7333e2

Please sign in to comment.