Skip to content

Commit 2d44f89

Browse files
committed
#24 Change Match type annotation from re to typing for the sake of compatibility of old Python.
1 parent fb852e1 commit 2d44f89

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

numdoclint/helper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33

44
import re
5-
from typing import Dict, List, Optional
5+
from typing import Dict, List, Match, Optional
66

77
ARGS_OR_KWARGS_NAME_LIST: List[str] = [
88
'*args',
@@ -72,7 +72,7 @@ def get_func_name_list(code_str: str) -> List[str]:
7272
break
7373
if not_func_str:
7474
continue
75-
match: Optional[re.Match] = _get_func_match(
75+
match: Optional[Match] = _get_func_match(
7676
py_module_str=code_str, func_name=func_name)
7777
if match is None:
7878
continue
@@ -210,7 +210,7 @@ def get_func_indent_num(py_module_str: str, func_name: str) -> int:
210210
ValueError
211211
If the target function can not be found.
212212
"""
213-
match: Optional[re.Match] = _get_func_match(
213+
match: Optional[Match] = _get_func_match(
214214
py_module_str=py_module_str, func_name=func_name)
215215
if match is None:
216216
err_msg = 'Target function not found: %s' % func_name
@@ -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[Match] = _get_func_match(
277277
py_module_str=py_module_str, func_name=func_name)
278278
if match is None:
279279
return ''
@@ -366,7 +366,7 @@ def _type_anotation_comment_exists(line_str: str) -> bool:
366366
return result
367367

368368

369-
def _get_func_match(py_module_str: str, func_name: str) -> Optional[re.Match]:
369+
def _get_func_match(py_module_str: str, func_name: str) -> Optional[Match]:
370370
"""
371371
Get a Match object of search result of target function.
372372

tests/test_helper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import re
2-
from typing import Dict, List, Optional
1+
from typing import Dict, List, Match, Optional
32

43
import pytest
54
import six
@@ -1686,7 +1685,7 @@ def sample_func
16861685
pass
16871686
"""
16881687

1689-
match: Optional[re.Match] = helper._get_func_match(
1688+
match: Optional[Match] = helper._get_func_match(
16901689
py_module_str=py_module_str, func_name='sample_func_1')
16911690
start_idx: int = match.start()
16921691
expected_func_str: str = 'def sample_func_1():'

tests/test_jupyter_notebook.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,13 @@ def test_check_jupyter_notebook() -> None:
344344

345345

346346
def test_check_jupyter_notebook_recursively() -> None:
347-
info_list: List[dict] = jupyter_notebook.check_jupyter_notebook_recursively(
348-
dir_path='./numdoclint/',
349-
verbose=jupyter_notebook.VERBOSE_DISABLED,
350-
ignore_func_name_prefix_list=[],
351-
ignore_info_id_list=[],
352-
enable_default_or_optional_doc_check=True)
347+
info_list: List[dict] = \
348+
jupyter_notebook.check_jupyter_notebook_recursively(
349+
dir_path='./numdoclint/',
350+
verbose=jupyter_notebook.VERBOSE_DISABLED,
351+
ignore_func_name_prefix_list=[],
352+
ignore_info_id_list=[],
353+
enable_default_or_optional_doc_check=True)
353354
assert info_list == []
354355

355356
info_list = jupyter_notebook.check_jupyter_notebook_recursively(

0 commit comments

Comments
 (0)