Skip to content

Commit

Permalink
#19 Apply each lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-ritchie committed Dec 12, 2020
1 parent bd767de commit 93183ff
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 45 deletions.
4 changes: 2 additions & 2 deletions numdoclint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _validate_args(
"""
if path is None:
err_msg: str = 'A path is not specified in the argument. '\
'Please set the `-p` or `--path` argument.'
'Please set the `-p` or `--path` argument.'
raise Exception(err_msg)
info_id_list = py_module.get_info_id_list()
for ignore_info_id in ignore_info_id_list:
Expand Down Expand Up @@ -165,7 +165,7 @@ def _exec_numdoclint(


def main(
args: Optional[argparse.Namespace]=None,
args: Optional[argparse.Namespace] = None,
return_list: bool = False) -> List[dict]:
"""
The function of command line entry point.
Expand Down
21 changes: 11 additions & 10 deletions numdoclint/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
]
ARG_NAME_LIST_TO_IGNORE.extend(ARGS_OR_KWARGS_NAME_LIST)

ADDITIONAL_INFO_PREFIX_LIST: List[str]= [
ADDITIONAL_INFO_PREFIX_LIST: List[str] = [
'.. versionadded',
'.. deprecated',
'.. versionchanged',
Expand Down Expand Up @@ -273,7 +273,7 @@ def get_func_overall_docstring(
docstring : str
Target docstring string.
"""
match: Optional[re.Match]= _get_func_match(
match: Optional[re.Match] = _get_func_match(
py_module_str=py_module_str, func_name=func_name)
if match is None:
return ''
Expand Down Expand Up @@ -499,7 +499,8 @@ def get_docstring_param_info_list(docstring: str) -> List[Dict[str, str]]:
for splitted_param_doc in splitted_param_doc_list:
arg_name: str = _get_docstring_var_name(var_doc=splitted_param_doc)
type_name: str = _get_docstring_type_name(var_doc=splitted_param_doc)
default_val: str = _get_docstring_default_value(var_doc=splitted_param_doc)
default_val: str = _get_docstring_default_value(
var_doc=splitted_param_doc)
description: str = _get_docstring_var_description(
var_doc=splitted_param_doc)
param_info_list = _append_param_info_to_list(
Expand Down Expand Up @@ -1063,7 +1064,7 @@ def _get_return_value_type_name_from_line(line_str: str) -> str:
return_value_type_name : str
Type name of return value.
"""
colon_exists: bool= ':' in line_str
colon_exists: bool = ':' in line_str
if not colon_exists:
return_value_type_name: str = line_str.split(':')[0]
else:
Expand All @@ -1073,7 +1074,7 @@ def _get_return_value_type_name_from_line(line_str: str) -> str:


def _get_return_value_docstring(
docstring: str, drop_additional_info: bool=True) -> str:
docstring: str, drop_additional_info: bool = True) -> str:
"""
Get the string of docstring's return value part.
Expand Down Expand Up @@ -1113,7 +1114,7 @@ def _get_return_value_docstring(
if i < start_line_idx:
continue
last_line_idx = i
is_hyphen_line: bool= '----' in line_str
is_hyphen_line: bool = '----' in line_str
if not is_hyphen_line:
continue
last_line_idx -= 2
Expand Down Expand Up @@ -1160,7 +1161,7 @@ def _hyphens_exists_next_line(
if len(line_splitted_list) < next_line_idx + 1:
return False
next_line_str: str = line_splitted_list[next_line_idx]
is_in: bool= '----' in next_line_str
is_in: bool = '----' in next_line_str
if is_in:
return True
return False
Expand Down Expand Up @@ -1306,7 +1307,7 @@ def _remove_nested_func_str(func_str: str, func_indent_num: int) -> str:
"""

removed_func_str: str = ''
line_splitted_list: List[str]= func_str.split('\n')
line_splitted_list: List[str] = func_str.split('\n')
is_initial_function_appeared: bool = False
is_nested_func_line: bool = False
for line_str in line_splitted_list:
Expand Down Expand Up @@ -1402,7 +1403,7 @@ def get_optional_arg_name_list(docstring: str) -> List[str]:
return []
if not _parameters_exists_in_docstring(docstring=docstring):
return []
splitted_param_doc_list: List[str]= get_splitted_param_doc_list(
splitted_param_doc_list: List[str] = get_splitted_param_doc_list(
docstring=docstring)
optional_arg_name_list: List[str] = []
for splitted_param_doc in splitted_param_doc_list:
Expand Down Expand Up @@ -1434,7 +1435,7 @@ def args_or_kwargs_str_in_param_name(param_arg_name: str) -> bool:

param_arg_name = param_arg_name.strip()
for args_or_kwargs_str in ARGS_OR_KWARGS_NAME_LIST:
is_in: bool= args_or_kwargs_str in param_arg_name
is_in: bool = args_or_kwargs_str in param_arg_name
if is_in:
return True
return False
Expand Down
6 changes: 3 additions & 3 deletions numdoclint/jupyter_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def check_jupyter_notebook(
notebook_data_dict=notebook_data_dict)
if not code_cell_str_list:
return []
info_list: List[dict]= []
info_list: List[dict] = []
enable_def_or_opt_check: bool = enable_default_or_optional_doc_check
for i, code_cell_str in enumerate(code_cell_str_list):
info_list_unit: List[dict] = _check_unit_code_cell_str(
Expand Down Expand Up @@ -196,7 +196,7 @@ def _check_jupyter_notebook_recursively(
continue
if not path.endswith('.ipynb'):
continue
unit_info_list: List[dict]= check_jupyter_notebook(
unit_info_list: List[dict] = check_jupyter_notebook(
notebook_path=path,
verbose=verbose,
ignore_func_name_prefix_list=ignore_func_name_prefix_list,
Expand Down Expand Up @@ -288,7 +288,7 @@ def _check_unit_code_cell_str(
if not func_name_list:
return []
info_list: List[dict] = []
enable_def_or_opt_check: bool= enable_default_or_optional_doc_check
enable_def_or_opt_check: bool = enable_default_or_optional_doc_check
for func_name in func_name_list:
is_func_name_to_ignore: bool = py_module.is_func_name_to_ignore(
func_name=func_name,
Expand Down
10 changes: 5 additions & 5 deletions numdoclint/py_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def check_python_module_recursively(
- info_id : int -> Identification number of which information.
- info : str -> Information of check result.
"""
enable_def_or_opt_check: bool= enable_default_or_optional_doc_check
enable_def_or_opt_check: bool = enable_default_or_optional_doc_check
info_list = _check_python_module_recursively(
dir_path=dir_path, info_list=[], verbose=verbose,
ignore_func_name_prefix_list=ignore_func_name_prefix_list,
Expand Down Expand Up @@ -213,7 +213,7 @@ def _print_info_list(info_list: List[dict], verbose: int) -> str:

def _check_python_module_recursively(
dir_path: str, info_list: List[dict], verbose: int = 1,
ignore_func_name_prefix_list: List[str]=['test_'],
ignore_func_name_prefix_list: List[str] = ['test_'],
ignore_info_id_list: List[int] = [],
enable_default_or_optional_doc_check: bool = False,
skip_decorator_name_list: List[str] = ['Appender']) -> List[dict]:
Expand Down Expand Up @@ -376,7 +376,7 @@ def get_single_func_info_list(
module_str=code_str, func_name=func_name)
kwargs_exists: bool = helper.kwargs_exists(
py_module_str=code_str, func_name=func_name)
decorator_names: List[str]= helper.get_decorator_names(
decorator_names: List[str] = helper.get_decorator_names(
py_module_str=code_str, func_name=func_name)
joined_decorator_names: str = ' '.join(decorator_names)
for skip_decorator_name in skip_decorator_name_list:
Expand Down Expand Up @@ -749,8 +749,8 @@ def _check_lacked_default_value(
if default_val_info_dict[param_info_arg_name] == '':
continue
info: str = 'While there is no description of default value'\
' in docstring, there is a default value on the'\
' argument side.'
' in docstring, there is a default value on the'\
' argument side.'
info += f'\nArgument name: {param_info_arg_name}'
info += '\nArgument default value: %s' \
% default_val_info_dict[param_info_arg_name]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def sample_func_2(price=100):
required=True)
for info_dict in info_list:
schema(info_dict)
info_id_list: List[int]= [
info_id_list: List[int] = [
info_dict[py_module.INFO_KEY_INFO_ID] for info_dict in info_list]
info_list = cli._exec_numdoclint(
path=TMP_TEST_MODULE_PATH_1,
Expand Down Expand Up @@ -409,11 +409,11 @@ class Args:
skip_decorator_name_list: List[str] = []

args: Args = Args()
info_list: List[dict]= cli.main(
info_list: List[dict] = cli.main(
args=args, # type: ignore
return_list=True)
assert info_list
schema: Schema= Schema(
schema: Schema = Schema(
schema={
py_module.INFO_KEY_MODULE_PATH: TMP_TEST_MODULE_PATH_1,
py_module.INFO_KEY_FUNC_NAME: 'sample_func_1',
Expand Down
22 changes: 11 additions & 11 deletions tests/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def test_get_param_docstring() -> None:
"""

param_docstring = helper.get_param_docstring(docstring=docstring)
expected_docstring: str= """ name : str
expected_docstring: str = """ name : str
Sample name.
location_id : int
Sample location id."""
Expand Down Expand Up @@ -756,7 +756,7 @@ def sample_func_7
def sample_func_8(dict_val: Optional[Dict[str, int]] = None):
pass
"""
args_str: str= helper._get_args_str(
args_str: str = helper._get_args_str(
code_str=code_str, func_name='sample_func_1')
assert args_str == ''

Expand Down Expand Up @@ -1055,7 +1055,7 @@ def test_get_docstring_return_val_info_list() -> None:
price : int
Sample price.
"""
return_val_info_list: List[Dict[str, str]]= \
return_val_info_list: List[Dict[str, str]] = \
helper.get_docstring_return_val_info_list(
docstring=docstring)
assert return_val_info_list == []
Expand Down Expand Up @@ -1309,7 +1309,7 @@ def test__parameters_exists_in_docstring() -> None:
name : str
Sample name.
"""
result_bool: bool= helper._parameters_exists_in_docstring(
result_bool: bool = helper._parameters_exists_in_docstring(
docstring=docstring)
assert result_bool

Expand Down Expand Up @@ -1484,7 +1484,7 @@ def sample_func_2(price):
pass
"""

result_bool: bool= helper.kwargs_exists(
result_bool: bool = helper.kwargs_exists(
py_module_str=py_module_str, func_name='sample_func_1')
assert result_bool

Expand Down Expand Up @@ -1512,7 +1512,7 @@ def test_args_or_kwargs_str_in_param_name() -> None:


def test__append_param_info_to_list() -> None:
param_info_list: List[Dict[str, str]]= helper._append_param_info_to_list(
param_info_list: List[Dict[str, str]] = helper._append_param_info_to_list(
param_info_list=[],
arg_name='price',
type_name='int',
Expand Down Expand Up @@ -1550,14 +1550,14 @@ def test__append_param_info_to_list() -> None:


def test__hyphens_exists_next_line() -> None:
line_splitted_list: List[str]= [
line_splitted_list: List[str] = [
'Sample docstring',
'',
'Parameters',
'----------',
]

result_bool: bool= helper._hyphens_exists_next_line(
result_bool: bool = helper._hyphens_exists_next_line(
line_splitted_list=line_splitted_list,
next_line_idx=4)
assert not result_bool
Expand Down Expand Up @@ -1634,7 +1634,7 @@ def sample_func_3(price):
pass
"""

decorator_names: List[str]= helper.get_decorator_names(
decorator_names: List[str] = helper.get_decorator_names(
py_module_str=py_module_str, func_name='sample_func_1')
assert decorator_names == []

Expand Down Expand Up @@ -1675,7 +1675,7 @@ def sample_func
pass
"""

match: Optional[re.Match]= helper._get_func_match(
match: Optional[re.Match] = helper._get_func_match(
py_module_str=py_module_str, func_name='sample_func_1')
start_idx: int = match.start()
expected_func_str: str = 'def sample_func_1():'
Expand Down Expand Up @@ -1720,7 +1720,7 @@ def sample_func_1():
pass
'''

result_bool: bool= helper.is_interactive_shell_example_line(
result_bool: bool = helper.is_interactive_shell_example_line(
func_start_index=5, py_module_str=py_module_str)
assert not result_bool

Expand Down
10 changes: 5 additions & 5 deletions tests/test_jupyter_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test__get_code_cell_str_list() -> None:


def test__rename_dict_key() -> None:
info_list: List[dict]= [{
info_list: List[dict] = [{
py_module.INFO_KEY_MODULE_PATH: 'sample/path.ipynb',
py_module.INFO_KEY_FUNC_NAME: 'sample_func_1',
py_module.INFO_KEY_INFO_ID: 1,
Expand Down Expand Up @@ -136,12 +136,12 @@ def test__rename_dict_key() -> None:


def test__add_code_cell_index() -> None:
info_list: List[dict]= [{}, {}]
info_list: List[dict] = [{}, {}]
info_list = jupyter_notebook._add_code_cell_index(
info_list=info_list,
code_cell_idx=5)
assert len(info_list) == 2
schema: Schema= Schema(
schema: Schema = Schema(
schema={
jupyter_notebook.INFO_KEY_CODE_CELL_INDEX: 5,
},
Expand All @@ -166,7 +166,7 @@ def test__check_unit_code_cell_str() -> None:
enable_default_or_optional_doc_check=False)
assert info_list == []

schema: Schema= Schema(
schema: Schema = Schema(
schema={
jupyter_notebook.INFO_KEY_NOTEBOOK_PATH: STR_SCHEMA,
jupyter_notebook.INFO_KEY_CODE_CELL_INDEX: int,
Expand Down Expand Up @@ -312,7 +312,7 @@ def test_check_jupyter_notebook() -> None:
schema(info_dict)
assert len(info_list) >= 10

ignore_info_id_list: List[int]= [
ignore_info_id_list: List[int] = [
info_dict[jupyter_notebook.INFO_KEY_INFO_ID]
for info_dict in info_list]

Expand Down
12 changes: 6 additions & 6 deletions tests/test_py_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def test__check_lacked_default_value() -> None:
default_val_info_dict=default_val_info_dict,
optional_arg_name_list=[])
assert len(info_list) == 2
schema_1: Schema= Schema(
schema_1: Schema = Schema(
schema={
py_module.INFO_KEY_MODULE_PATH: expected_module_path,
py_module.INFO_KEY_FUNC_NAME: expected_func_name,
Expand All @@ -327,7 +327,7 @@ def test__check_lacked_default_value() -> None:
},
required=True)
schema_1(info_list[0])
schema_2: Schema= Schema(
schema_2: Schema = Schema(
schema={
py_module.INFO_KEY_MODULE_PATH: expected_module_path,
py_module.INFO_KEY_FUNC_NAME: expected_func_name,
Expand Down Expand Up @@ -814,7 +814,7 @@ def _exec_target_func(
with open(TMP_TEST_MODULE_PATH, 'w') as f:
f.write(module_str)

info_list: List[dict]= _exec_target_func(func_name='sample_func_1')
info_list: List[dict] = _exec_target_func(func_name='sample_func_1')
_check_info_list_schema(info_list=info_list)
_check_info_id_is_in_list(
expected_info_id=py_module.INFO_ID_LACKED_FUNC_DESCRIPTION,
Expand Down Expand Up @@ -920,7 +920,7 @@ def test_check_python_module() -> None:
"""
with open(TMP_TEST_MODULE_PATH, 'w') as f:
f.write(module_str)
info_list: List[dict]= py_module.check_python_module(
info_list: List[dict] = py_module.check_python_module(
py_module_path=TMP_TEST_MODULE_PATH,
enable_default_or_optional_doc_check=True)
assert info_list == []
Expand Down Expand Up @@ -1138,7 +1138,7 @@ def sample_func_3(price=100):
def sample_func_4(price):
pass
'''
module_path_5: str= os.path.join(child_dir_path, 'test_module_5.py')
module_path_5: str = os.path.join(child_dir_path, 'test_module_5.py')
with open(module_path_5, 'w') as f:
f.write(module_str_5)
info_list = py_module.check_python_module_recursively(
Expand Down Expand Up @@ -1186,7 +1186,7 @@ def test__print_info_list() -> None:

def test_is_func_name_to_ignore() -> None:
ignore_func_name_prefix_list: List[str] = ['test_', 'sample_']
result_bool: bool= py_module.is_func_name_to_ignore(
result_bool: bool = py_module.is_func_name_to_ignore(
func_name='test_get_name',
ignore_func_name_prefix_list=ignore_func_name_prefix_list)
assert result_bool
Expand Down

0 comments on commit 93183ff

Please sign in to comment.