Skip to content

Commit 93183ff

Browse files
committed
#19 Apply each lints.
1 parent bd767de commit 93183ff

8 files changed

+46
-45
lines changed

numdoclint/cli.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def _validate_args(
5252
"""
5353
if path is None:
5454
err_msg: str = 'A path is not specified in the argument. '\
55-
'Please set the `-p` or `--path` argument.'
55+
'Please set the `-p` or `--path` argument.'
5656
raise Exception(err_msg)
5757
info_id_list = py_module.get_info_id_list()
5858
for ignore_info_id in ignore_info_id_list:
@@ -165,7 +165,7 @@ def _exec_numdoclint(
165165

166166

167167
def main(
168-
args: Optional[argparse.Namespace]=None,
168+
args: Optional[argparse.Namespace] = None,
169169
return_list: bool = False) -> List[dict]:
170170
"""
171171
The function of command line entry point.

numdoclint/helper.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
]
1818
ARG_NAME_LIST_TO_IGNORE.extend(ARGS_OR_KWARGS_NAME_LIST)
1919

20-
ADDITIONAL_INFO_PREFIX_LIST: List[str]= [
20+
ADDITIONAL_INFO_PREFIX_LIST: List[str] = [
2121
'.. versionadded',
2222
'.. deprecated',
2323
'.. versionchanged',
@@ -273,7 +273,7 @@ def get_func_overall_docstring(
273273
docstring : str
274274
Target docstring string.
275275
"""
276-
match: Optional[re.Match]= _get_func_match(
276+
match: Optional[re.Match] = _get_func_match(
277277
py_module_str=py_module_str, func_name=func_name)
278278
if match is None:
279279
return ''
@@ -499,7 +499,8 @@ def get_docstring_param_info_list(docstring: str) -> List[Dict[str, str]]:
499499
for splitted_param_doc in splitted_param_doc_list:
500500
arg_name: str = _get_docstring_var_name(var_doc=splitted_param_doc)
501501
type_name: str = _get_docstring_type_name(var_doc=splitted_param_doc)
502-
default_val: str = _get_docstring_default_value(var_doc=splitted_param_doc)
502+
default_val: str = _get_docstring_default_value(
503+
var_doc=splitted_param_doc)
503504
description: str = _get_docstring_var_description(
504505
var_doc=splitted_param_doc)
505506
param_info_list = _append_param_info_to_list(
@@ -1063,7 +1064,7 @@ def _get_return_value_type_name_from_line(line_str: str) -> str:
10631064
return_value_type_name : str
10641065
Type name of return value.
10651066
"""
1066-
colon_exists: bool= ':' in line_str
1067+
colon_exists: bool = ':' in line_str
10671068
if not colon_exists:
10681069
return_value_type_name: str = line_str.split(':')[0]
10691070
else:
@@ -1073,7 +1074,7 @@ def _get_return_value_type_name_from_line(line_str: str) -> str:
10731074

10741075

10751076
def _get_return_value_docstring(
1076-
docstring: str, drop_additional_info: bool=True) -> str:
1077+
docstring: str, drop_additional_info: bool = True) -> str:
10771078
"""
10781079
Get the string of docstring's return value part.
10791080
@@ -1113,7 +1114,7 @@ def _get_return_value_docstring(
11131114
if i < start_line_idx:
11141115
continue
11151116
last_line_idx = i
1116-
is_hyphen_line: bool= '----' in line_str
1117+
is_hyphen_line: bool = '----' in line_str
11171118
if not is_hyphen_line:
11181119
continue
11191120
last_line_idx -= 2
@@ -1160,7 +1161,7 @@ def _hyphens_exists_next_line(
11601161
if len(line_splitted_list) < next_line_idx + 1:
11611162
return False
11621163
next_line_str: str = line_splitted_list[next_line_idx]
1163-
is_in: bool= '----' in next_line_str
1164+
is_in: bool = '----' in next_line_str
11641165
if is_in:
11651166
return True
11661167
return False
@@ -1306,7 +1307,7 @@ def _remove_nested_func_str(func_str: str, func_indent_num: int) -> str:
13061307
"""
13071308

13081309
removed_func_str: str = ''
1309-
line_splitted_list: List[str]= func_str.split('\n')
1310+
line_splitted_list: List[str] = func_str.split('\n')
13101311
is_initial_function_appeared: bool = False
13111312
is_nested_func_line: bool = False
13121313
for line_str in line_splitted_list:
@@ -1402,7 +1403,7 @@ def get_optional_arg_name_list(docstring: str) -> List[str]:
14021403
return []
14031404
if not _parameters_exists_in_docstring(docstring=docstring):
14041405
return []
1405-
splitted_param_doc_list: List[str]= get_splitted_param_doc_list(
1406+
splitted_param_doc_list: List[str] = get_splitted_param_doc_list(
14061407
docstring=docstring)
14071408
optional_arg_name_list: List[str] = []
14081409
for splitted_param_doc in splitted_param_doc_list:
@@ -1434,7 +1435,7 @@ def args_or_kwargs_str_in_param_name(param_arg_name: str) -> bool:
14341435

14351436
param_arg_name = param_arg_name.strip()
14361437
for args_or_kwargs_str in ARGS_OR_KWARGS_NAME_LIST:
1437-
is_in: bool= args_or_kwargs_str in param_arg_name
1438+
is_in: bool = args_or_kwargs_str in param_arg_name
14381439
if is_in:
14391440
return True
14401441
return False

numdoclint/jupyter_notebook.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def check_jupyter_notebook(
7575
notebook_data_dict=notebook_data_dict)
7676
if not code_cell_str_list:
7777
return []
78-
info_list: List[dict]= []
78+
info_list: List[dict] = []
7979
enable_def_or_opt_check: bool = enable_default_or_optional_doc_check
8080
for i, code_cell_str in enumerate(code_cell_str_list):
8181
info_list_unit: List[dict] = _check_unit_code_cell_str(
@@ -196,7 +196,7 @@ def _check_jupyter_notebook_recursively(
196196
continue
197197
if not path.endswith('.ipynb'):
198198
continue
199-
unit_info_list: List[dict]= check_jupyter_notebook(
199+
unit_info_list: List[dict] = check_jupyter_notebook(
200200
notebook_path=path,
201201
verbose=verbose,
202202
ignore_func_name_prefix_list=ignore_func_name_prefix_list,
@@ -288,7 +288,7 @@ def _check_unit_code_cell_str(
288288
if not func_name_list:
289289
return []
290290
info_list: List[dict] = []
291-
enable_def_or_opt_check: bool= enable_default_or_optional_doc_check
291+
enable_def_or_opt_check: bool = enable_default_or_optional_doc_check
292292
for func_name in func_name_list:
293293
is_func_name_to_ignore: bool = py_module.is_func_name_to_ignore(
294294
func_name=func_name,

numdoclint/py_module.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def check_python_module_recursively(
140140
- info_id : int -> Identification number of which information.
141141
- info : str -> Information of check result.
142142
"""
143-
enable_def_or_opt_check: bool= enable_default_or_optional_doc_check
143+
enable_def_or_opt_check: bool = enable_default_or_optional_doc_check
144144
info_list = _check_python_module_recursively(
145145
dir_path=dir_path, info_list=[], verbose=verbose,
146146
ignore_func_name_prefix_list=ignore_func_name_prefix_list,
@@ -213,7 +213,7 @@ def _print_info_list(info_list: List[dict], verbose: int) -> str:
213213

214214
def _check_python_module_recursively(
215215
dir_path: str, info_list: List[dict], verbose: int = 1,
216-
ignore_func_name_prefix_list: List[str]=['test_'],
216+
ignore_func_name_prefix_list: List[str] = ['test_'],
217217
ignore_info_id_list: List[int] = [],
218218
enable_default_or_optional_doc_check: bool = False,
219219
skip_decorator_name_list: List[str] = ['Appender']) -> List[dict]:
@@ -376,7 +376,7 @@ def get_single_func_info_list(
376376
module_str=code_str, func_name=func_name)
377377
kwargs_exists: bool = helper.kwargs_exists(
378378
py_module_str=code_str, func_name=func_name)
379-
decorator_names: List[str]= helper.get_decorator_names(
379+
decorator_names: List[str] = helper.get_decorator_names(
380380
py_module_str=code_str, func_name=func_name)
381381
joined_decorator_names: str = ' '.join(decorator_names)
382382
for skip_decorator_name in skip_decorator_name_list:
@@ -749,8 +749,8 @@ def _check_lacked_default_value(
749749
if default_val_info_dict[param_info_arg_name] == '':
750750
continue
751751
info: str = 'While there is no description of default value'\
752-
' in docstring, there is a default value on the'\
753-
' argument side.'
752+
' in docstring, there is a default value on the'\
753+
' argument side.'
754754
info += f'\nArgument name: {param_info_arg_name}'
755755
info += '\nArgument default value: %s' \
756756
% default_val_info_dict[param_info_arg_name]

tests/test_cli.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def sample_func_2(price=100):
156156
required=True)
157157
for info_dict in info_list:
158158
schema(info_dict)
159-
info_id_list: List[int]= [
159+
info_id_list: List[int] = [
160160
info_dict[py_module.INFO_KEY_INFO_ID] for info_dict in info_list]
161161
info_list = cli._exec_numdoclint(
162162
path=TMP_TEST_MODULE_PATH_1,
@@ -409,11 +409,11 @@ class Args:
409409
skip_decorator_name_list: List[str] = []
410410

411411
args: Args = Args()
412-
info_list: List[dict]= cli.main(
412+
info_list: List[dict] = cli.main(
413413
args=args, # type: ignore
414414
return_list=True)
415415
assert info_list
416-
schema: Schema= Schema(
416+
schema: Schema = Schema(
417417
schema={
418418
py_module.INFO_KEY_MODULE_PATH: TMP_TEST_MODULE_PATH_1,
419419
py_module.INFO_KEY_FUNC_NAME: 'sample_func_1',

tests/test_helper.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def test_get_param_docstring() -> None:
467467
"""
468468

469469
param_docstring = helper.get_param_docstring(docstring=docstring)
470-
expected_docstring: str= """ name : str
470+
expected_docstring: str = """ name : str
471471
Sample name.
472472
location_id : int
473473
Sample location id."""
@@ -756,7 +756,7 @@ def sample_func_7
756756
def sample_func_8(dict_val: Optional[Dict[str, int]] = None):
757757
pass
758758
"""
759-
args_str: str= helper._get_args_str(
759+
args_str: str = helper._get_args_str(
760760
code_str=code_str, func_name='sample_func_1')
761761
assert args_str == ''
762762

@@ -1055,7 +1055,7 @@ def test_get_docstring_return_val_info_list() -> None:
10551055
price : int
10561056
Sample price.
10571057
"""
1058-
return_val_info_list: List[Dict[str, str]]= \
1058+
return_val_info_list: List[Dict[str, str]] = \
10591059
helper.get_docstring_return_val_info_list(
10601060
docstring=docstring)
10611061
assert return_val_info_list == []
@@ -1309,7 +1309,7 @@ def test__parameters_exists_in_docstring() -> None:
13091309
name : str
13101310
Sample name.
13111311
"""
1312-
result_bool: bool= helper._parameters_exists_in_docstring(
1312+
result_bool: bool = helper._parameters_exists_in_docstring(
13131313
docstring=docstring)
13141314
assert result_bool
13151315

@@ -1484,7 +1484,7 @@ def sample_func_2(price):
14841484
pass
14851485
"""
14861486

1487-
result_bool: bool= helper.kwargs_exists(
1487+
result_bool: bool = helper.kwargs_exists(
14881488
py_module_str=py_module_str, func_name='sample_func_1')
14891489
assert result_bool
14901490

@@ -1512,7 +1512,7 @@ def test_args_or_kwargs_str_in_param_name() -> None:
15121512

15131513

15141514
def test__append_param_info_to_list() -> None:
1515-
param_info_list: List[Dict[str, str]]= helper._append_param_info_to_list(
1515+
param_info_list: List[Dict[str, str]] = helper._append_param_info_to_list(
15161516
param_info_list=[],
15171517
arg_name='price',
15181518
type_name='int',
@@ -1550,14 +1550,14 @@ def test__append_param_info_to_list() -> None:
15501550

15511551

15521552
def test__hyphens_exists_next_line() -> None:
1553-
line_splitted_list: List[str]= [
1553+
line_splitted_list: List[str] = [
15541554
'Sample docstring',
15551555
'',
15561556
'Parameters',
15571557
'----------',
15581558
]
15591559

1560-
result_bool: bool= helper._hyphens_exists_next_line(
1560+
result_bool: bool = helper._hyphens_exists_next_line(
15611561
line_splitted_list=line_splitted_list,
15621562
next_line_idx=4)
15631563
assert not result_bool
@@ -1634,7 +1634,7 @@ def sample_func_3(price):
16341634
pass
16351635
"""
16361636

1637-
decorator_names: List[str]= helper.get_decorator_names(
1637+
decorator_names: List[str] = helper.get_decorator_names(
16381638
py_module_str=py_module_str, func_name='sample_func_1')
16391639
assert decorator_names == []
16401640

@@ -1675,7 +1675,7 @@ def sample_func
16751675
pass
16761676
"""
16771677

1678-
match: Optional[re.Match]= helper._get_func_match(
1678+
match: Optional[re.Match] = helper._get_func_match(
16791679
py_module_str=py_module_str, func_name='sample_func_1')
16801680
start_idx: int = match.start()
16811681
expected_func_str: str = 'def sample_func_1():'
@@ -1720,7 +1720,7 @@ def sample_func_1():
17201720
pass
17211721
'''
17221722

1723-
result_bool: bool= helper.is_interactive_shell_example_line(
1723+
result_bool: bool = helper.is_interactive_shell_example_line(
17241724
func_start_index=5, py_module_str=py_module_str)
17251725
assert not result_bool
17261726

tests/test_jupyter_notebook.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test__get_code_cell_str_list() -> None:
107107

108108

109109
def test__rename_dict_key() -> None:
110-
info_list: List[dict]= [{
110+
info_list: List[dict] = [{
111111
py_module.INFO_KEY_MODULE_PATH: 'sample/path.ipynb',
112112
py_module.INFO_KEY_FUNC_NAME: 'sample_func_1',
113113
py_module.INFO_KEY_INFO_ID: 1,
@@ -136,12 +136,12 @@ def test__rename_dict_key() -> None:
136136

137137

138138
def test__add_code_cell_index() -> None:
139-
info_list: List[dict]= [{}, {}]
139+
info_list: List[dict] = [{}, {}]
140140
info_list = jupyter_notebook._add_code_cell_index(
141141
info_list=info_list,
142142
code_cell_idx=5)
143143
assert len(info_list) == 2
144-
schema: Schema= Schema(
144+
schema: Schema = Schema(
145145
schema={
146146
jupyter_notebook.INFO_KEY_CODE_CELL_INDEX: 5,
147147
},
@@ -166,7 +166,7 @@ def test__check_unit_code_cell_str() -> None:
166166
enable_default_or_optional_doc_check=False)
167167
assert info_list == []
168168

169-
schema: Schema= Schema(
169+
schema: Schema = Schema(
170170
schema={
171171
jupyter_notebook.INFO_KEY_NOTEBOOK_PATH: STR_SCHEMA,
172172
jupyter_notebook.INFO_KEY_CODE_CELL_INDEX: int,
@@ -312,7 +312,7 @@ def test_check_jupyter_notebook() -> None:
312312
schema(info_dict)
313313
assert len(info_list) >= 10
314314

315-
ignore_info_id_list: List[int]= [
315+
ignore_info_id_list: List[int] = [
316316
info_dict[jupyter_notebook.INFO_KEY_INFO_ID]
317317
for info_dict in info_list]
318318

tests/test_py_module.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def test__check_lacked_default_value() -> None:
317317
default_val_info_dict=default_val_info_dict,
318318
optional_arg_name_list=[])
319319
assert len(info_list) == 2
320-
schema_1: Schema= Schema(
320+
schema_1: Schema = Schema(
321321
schema={
322322
py_module.INFO_KEY_MODULE_PATH: expected_module_path,
323323
py_module.INFO_KEY_FUNC_NAME: expected_func_name,
@@ -327,7 +327,7 @@ def test__check_lacked_default_value() -> None:
327327
},
328328
required=True)
329329
schema_1(info_list[0])
330-
schema_2: Schema= Schema(
330+
schema_2: Schema = Schema(
331331
schema={
332332
py_module.INFO_KEY_MODULE_PATH: expected_module_path,
333333
py_module.INFO_KEY_FUNC_NAME: expected_func_name,
@@ -814,7 +814,7 @@ def _exec_target_func(
814814
with open(TMP_TEST_MODULE_PATH, 'w') as f:
815815
f.write(module_str)
816816

817-
info_list: List[dict]= _exec_target_func(func_name='sample_func_1')
817+
info_list: List[dict] = _exec_target_func(func_name='sample_func_1')
818818
_check_info_list_schema(info_list=info_list)
819819
_check_info_id_is_in_list(
820820
expected_info_id=py_module.INFO_ID_LACKED_FUNC_DESCRIPTION,
@@ -920,7 +920,7 @@ def test_check_python_module() -> None:
920920
"""
921921
with open(TMP_TEST_MODULE_PATH, 'w') as f:
922922
f.write(module_str)
923-
info_list: List[dict]= py_module.check_python_module(
923+
info_list: List[dict] = py_module.check_python_module(
924924
py_module_path=TMP_TEST_MODULE_PATH,
925925
enable_default_or_optional_doc_check=True)
926926
assert info_list == []
@@ -1138,7 +1138,7 @@ def sample_func_3(price=100):
11381138
def sample_func_4(price):
11391139
pass
11401140
'''
1141-
module_path_5: str= os.path.join(child_dir_path, 'test_module_5.py')
1141+
module_path_5: str = os.path.join(child_dir_path, 'test_module_5.py')
11421142
with open(module_path_5, 'w') as f:
11431143
f.write(module_str_5)
11441144
info_list = py_module.check_python_module_recursively(
@@ -1186,7 +1186,7 @@ def test__print_info_list() -> None:
11861186

11871187
def test_is_func_name_to_ignore() -> None:
11881188
ignore_func_name_prefix_list: List[str] = ['test_', 'sample_']
1189-
result_bool: bool= py_module.is_func_name_to_ignore(
1189+
result_bool: bool = py_module.is_func_name_to_ignore(
11901190
func_name='test_get_name',
11911191
ignore_func_name_prefix_list=ignore_func_name_prefix_list)
11921192
assert result_bool

0 commit comments

Comments
 (0)