Skip to content

Commit 6eda2f3

Browse files
author
takuya_sekiguchi
committed
Supported function type annotation comment (#15).
1 parent aec2da1 commit 6eda2f3

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ $ python ./run_all_tests_and_lint.py
672672
Command to run the entire test:
673673

674674
```
675-
$ pytest --cov=numdoclint tests/
675+
$ pytest --cov=numdoclint tests/ -v
676676
```
677677

678678
Command to run the autoflake:

numdoclint/helper.py

+21
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ def get_func_overall_docstring(
291291
if index == 0:
292292
func_str += line_str
293293
continue
294+
if _type_anotation_comment_exists(line_str=line_str):
295+
continue
294296
if (('"""' in line_str or "'''" in line_str)
295297
and (not is_docstring_line)):
296298
is_docstring_line = True
@@ -340,6 +342,25 @@ def get_func_overall_docstring(
340342
return docstring
341343

342344

345+
def _type_anotation_comment_exists(line_str):
346+
"""
347+
Get a boolean value whether type annotation comment exists
348+
in line or not.
349+
350+
Parameters
351+
----------
352+
line_str : str
353+
The target line string.
354+
355+
Returns
356+
-------
357+
result : bool
358+
If exists, True will be set.
359+
"""
360+
result = '# type: ' in line_str
361+
return result
362+
363+
343364
def _get_func_match(py_module_str, func_name):
344365
"""
345366
Get a Match object of search result of target function.

tests/test_helper.py

+24
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@ def sample_func_10(price):
280280
281281
Sample docstring."""
282282
pass
283+
284+
285+
def sample_func_11(price):
286+
# type: (int) -> None
287+
"""
288+
Sample function with type annotation comment.
289+
"""
283290
'''
284291
docstring = helper.get_func_overall_docstring(
285292
py_module_str=py_module_str, func_name='sample_func_0')
@@ -380,6 +387,13 @@ def sample_func_10(price):
380387
Sample docstring."""
381388
assert docstring == expected_docstring
382389

390+
docstring = helper.get_func_overall_docstring(
391+
py_module_str=py_module_str,
392+
func_name='sample_func_11')
393+
expected_docstring = \
394+
""" Sample function with type annotation comment"""
395+
assert docstring, expected_docstring
396+
383397

384398
def test__set_docstring_indent_number_to_one():
385399
docstring = """
@@ -1722,3 +1736,13 @@ def test__add_line_str():
17221736
assert target_str == 'abc'
17231737
target_str = helper._add_line_str(target_str='abc', line_str='def')
17241738
assert target_str == 'abc\ndef'
1739+
1740+
1741+
def test__type_anotation_comment_exists():
1742+
result = helper._type_anotation_comment_exists(
1743+
line_str='def sample_func():')
1744+
assert not result
1745+
1746+
result = helper._type_anotation_comment_exists(
1747+
line_str=' # type: (int) -> str')
1748+
assert result

0 commit comments

Comments
 (0)