Skip to content

Commit bb2d3ef

Browse files
committed
Lint
1 parent 5b2d330 commit bb2d3ef

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

flake8_sphinx_links/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ def __init__(self) -> None:
190190
def _check_docstring(self, node: Union[ast.ClassDef, ast.FunctionDef, ast.Module]) -> None:
191191
"""
192192
Check the docstring of a function, or a method of a class.
193+
194+
:param node:
193195
"""
194196

195197
docstring = ast.get_docstring(node, clean=False)
@@ -208,7 +210,7 @@ def _check_docstring(self, node: Union[ast.ClassDef, ast.FunctionDef, ast.Module
208210
if (
209211
sys.version_info < (3, 8) and platform.python_implementation() != "PyPy"
210212
): # pragma: no cover (PY38+ or PyPy)
211-
doc_end_lineno = node.body[0].value.lineno # type: ignore
213+
doc_end_lineno = node.body[0].value.lineno
212214

213215
# Calculate the start line
214216
doc_start_lineno = doc_end_lineno - doc_line_length
@@ -221,7 +223,7 @@ def _check_docstring(self, node: Union[ast.ClassDef, ast.FunctionDef, ast.Module
221223
doc_start_lineno += 1
222224

223225
else: # pragma: no cover (<PY38 and !PyPy)
224-
doc_start_lineno = node.body[0].value.lineno # type: ignore
226+
doc_start_lineno = node.body[0].value.lineno # type: ignore[attr-defined]
225227

226228
for offset, line in enumerate(docstring.splitlines()):
227229

tests/flake8_sphinx_links_test.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# stdlib
22
import ast
3-
from typing import Set
3+
from typing import Any, Set
44

55
# 3rd party
66
import pytest
@@ -14,7 +14,7 @@ def results(s: str) -> Set[str]:
1414

1515

1616
@pytest.mark.parametrize("obj", py_obj)
17-
def test_bad_docstring_py_obj(obj):
17+
def test_bad_docstring_py_obj(obj: Any):
1818
test_code = f'''"""
1919
2020
``{obj}``
@@ -41,12 +41,8 @@ def good_docstring():
4141
4242
'''
4343

44-
assert results(test_code
45-
) == { # noqa: sphinx_links001
46-
f"3:0: {SXL001}",
47-
f"8:0: {SXL001}",
48-
f"13:1: {SXL001}",
49-
}
44+
expected_results = {f"3:0: {SXL001}", f"8:0: {SXL001}", f"13:1: {SXL001}"}
45+
assert results(test_code) == expected_results
5046

5147

5248
@pytest.mark.parametrize("obj", py_obj_python)
@@ -77,16 +73,12 @@ class good_docstring():
7773
7874
'''
7975

80-
assert results(test_code
81-
) == { # noqa: sphinx_links001
82-
f"3:0: {SXL001}",
83-
f"8:0: {SXL001}",
84-
f"13:1: {SXL001}",
85-
}
76+
expected_results = {f"3:0: {SXL001}", f"8:0: {SXL001}", f"13:1: {SXL001}"}
77+
assert results(test_code) == expected_results
8678

8779

8880
@pytest.mark.parametrize("obj", exc)
89-
def test_bad_docstring_exc(obj):
81+
def test_bad_docstring_exc(obj: Any):
9082
test_code = f'''"""
9183
9284
``{obj}``
@@ -111,12 +103,8 @@ class good_docstring():
111103
112104
'''
113105

114-
assert results(test_code
115-
) == { # noqa: sphinx_links001
116-
f"3:0: {SXL001}",
117-
f"8:0: {SXL001}",
118-
f"12:0: {SXL001}",
119-
}
106+
expected_results = {f"3:0: {SXL001}", f"8:0: {SXL001}", f"12:0: {SXL001}"}
107+
assert results(test_code) == expected_results
120108

121109

122110
@pytest.mark.parametrize("obj", class_)
@@ -145,9 +133,5 @@ class good_docstring():
145133
146134
'''
147135

148-
assert results(test_code
149-
) == { # noqa: sphinx_links001
150-
f"3:0: {SXL001}",
151-
f"8:0: {SXL001}",
152-
f"13:1: {SXL001}",
153-
}
136+
expected_results = {f"3:0: {SXL001}", f"8:0: {SXL001}", f"13:1: {SXL001}"}
137+
assert results(test_code) == expected_results

0 commit comments

Comments
 (0)