Skip to content

Commit

Permalink
[Pylint] allow for spacing in type (#6405)
Browse files Browse the repository at this point in the history
* allow for spacing in type

* comments
  • Loading branch information
l0lawrence authored Jun 27, 2023
1 parent 1f51515 commit 77f07f3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,11 @@ def check_parameters(self, node):
if line.startswith("param") and line.count(" ") == 2:
_, param_type, param = line.split(" ")
docparams[param] = param_type
# if the param has its type on the same line with additional spaces
if line.startswith("param") and line.count(" ") > 2:
param = line.split(" ")[-1]
param_type = ("").join(line.split(" ")[1:-1])
docparams[param] = param_type
if line.startswith("type"):
param = line.split("type ")[1]
if param in docparams:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3480,4 +3480,30 @@ def function_foo(self) -> Dict[str,str]:
end_col_offset=16
),
):
self.checker.visit_functiondef(node)

def test_docstring_type_has_space(self):
# Don't error if there is extra spacing in the type
node = astroid.extract_node(
"""
def function_foo(x):
'''
:param dict[str, int] x: x
'''
"""
)
with self.assertNoMessages():
self.checker.visit_functiondef(node)

def test_docstring_type_has_many_spaces(self):
# Don't error if there is extra spacing around the type
node = astroid.extract_node(
"""
def function_foo(x):
'''
:param dict[str, int] x: x
'''
"""
)
with self.assertNoMessages():
self.checker.visit_functiondef(node)

0 comments on commit 77f07f3

Please sign in to comment.