Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pylint] allow for spacing in type #6405

Merged
merged 3 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
kristapratico marked this conversation as resolved.
Show resolved Hide resolved
'''
"""
)
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)