Skip to content

Commit ca44a24

Browse files
kasiumDanielNoord
andauthored
Disable bad-docstring-quotes for <= 3.7 (pylint-dev#5526)
In python 3.7 and below, the ast parser might return wrong line numbers. Closes pylint-dev#3077 Co-authored-by: Daniël van Noord <[email protected]>
1 parent 7b7cc54 commit ca44a24

12 files changed

+98
-26
lines changed

ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ Release date: TBA
184184

185185
Closes #5460
186186

187+
* Disable checker ``bad-docstring-quotes`` for Python <= 3.7, because in these versions the line
188+
numbers for decorated functions and classes are not reliable which interferes with the checker.
189+
190+
Closes #3077
191+
187192
* Fixed incorrect classification of Numpy-style docstring as Google-style docstring for
188193
docstrings with property setter documentation.
189194
Docstring classification is now based on the highest amount of matched sections instead

doc/whatsnew/2.13.rst

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ Extensions
3838
Docstring classification is now based on the highest amount of matched sections instead
3939
of the order in which the docstring styles were tried.
4040

41+
* ``DocStringStyleChecker``
42+
43+
* Disable checker ``bad-docstring-quotes`` for Python <= 3.7, because in these versions the line
44+
numbers for decorated functions and classes are not reliable which interferes with the checker.
45+
46+
Closes #3077
47+
4148
Other Changes
4249
=============
4350

pylint/extensions/docstyle.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from pylint import checkers
1919
from pylint.checkers.utils import check_messages
20+
from pylint.constants import PY38_PLUS
2021
from pylint.interfaces import HIGH, IAstroidChecker
2122

2223
if TYPE_CHECKING:
@@ -33,7 +34,8 @@ class DocStringStyleChecker(checkers.BaseChecker):
3334
"C0198": (
3435
'Bad docstring quotes in %s, expected """, given %s',
3536
"bad-docstring-quotes",
36-
"Used when a docstring does not have triple double quotes.",
37+
"Used when a docstring does not have triple double quotes. "
38+
"This checker only works on Python 3.8+.",
3739
),
3840
"C0199": (
3941
"First line empty in %s docstring",
@@ -81,7 +83,7 @@ def _check_docstring(self, node_type, node):
8183
quotes = "'"
8284
else:
8385
quotes = False
84-
if quotes:
86+
if quotes and PY38_PLUS:
8587
self.add_message(
8688
"bad-docstring-quotes",
8789
node=node,

tests/functional/ext/docstyle/docstyle.txt

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Checks of Dosctrings 'docstring-first-line-empty'"""
2+
# pylint: disable=too-few-public-methods,bad-docstring-quotes
3+
4+
def check_messages(*messages): # [docstring-first-line-empty]
5+
"""
6+
docstring"""
7+
return messages
8+
9+
10+
def function2():
11+
"""Test Ok"""
12+
13+
14+
class FFFF: # [docstring-first-line-empty]
15+
"""
16+
Test Docstring First Line Empty
17+
"""
18+
19+
def method1(self): # [docstring-first-line-empty]
20+
'''
21+
Test Triple Single Quotes docstring
22+
'''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
docstring-first-line-empty:4:0:7:19:check_messages:First line empty in function docstring:HIGH
2+
docstring-first-line-empty:14:0:22:11:FFFF:First line empty in class docstring:HIGH
3+
docstring-first-line-empty:19:4:22:11:FFFF.method1:First line empty in method docstring:HIGH
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Checks of Dosctrings 'bad-docstring-quotes'
2+
3+
Check that the checker is not enabled on python <= 3.7
4+
"""
5+
# pylint: disable=docstring-first-line-empty,missing-class-docstring, undefined-variable
6+
7+
8+
class FFFF:
9+
def method1(self):
10+
'''
11+
Test Triple Single Quotes docstring
12+
'''
13+
14+
def method2(self):
15+
"bad docstring 1"
16+
17+
def method3(self):
18+
'bad docstring 2'
19+
20+
def method4(self):
21+
' """bad docstring 3 '
22+
23+
@check_messages("bad-open-mode", "redundant-unittest-assert", "deprecated-module")
24+
def method5(self):
25+
"""Test OK 1 with decorators"""
26+
27+
def method6(self):
28+
r"""Test OK 2 with raw string"""
29+
30+
def method7(self):
31+
u"""Test OK 3 with unicode string"""
32+
33+
34+
def function2():
35+
"""Test Ok"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[MASTER]
2+
load-plugins=pylint.extensions.docstyle,
3+
4+
[testoptions]
5+
max_pyver=3.7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
"""Checks of Dosctrings 'docstring-first-line-empty' 'bad-docstring-quotes'"""
1+
"""Checks of Dosctrings 'bad-docstring-quotes'"""
2+
# pylint: disable=docstring-first-line-empty,missing-class-docstring, undefined-variable
23

34

4-
def check_messages(*messages): # [docstring-first-line-empty]
5-
"""
6-
docstring"""
7-
return messages
8-
9-
10-
def function2():
11-
"""Test Ok"""
12-
13-
14-
class FFFF: # [docstring-first-line-empty]
15-
"""
16-
Test Docstring First Line Empty
17-
"""
18-
19-
def method1(self): # [docstring-first-line-empty, bad-docstring-quotes]
5+
class FFFF:
6+
def method1(self): # [bad-docstring-quotes]
207
'''
218
Test Triple Single Quotes docstring
229
'''
@@ -39,3 +26,7 @@ def method6(self):
3926

4027
def method7(self):
4128
u"""Test OK 3 with unicode string"""
29+
30+
31+
def function2():
32+
"""Test Ok"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[MASTER]
2+
load-plugins=pylint.extensions.docstyle,
3+
4+
[testoptions]
5+
min_pyver=3.8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bad-docstring-quotes:6:4:9:11:FFFF.method1:"Bad docstring quotes in method, expected """""", given '''":HIGH
2+
bad-docstring-quotes:11:4:12:25:FFFF.method2:"Bad docstring quotes in method, expected """""", given """:HIGH
3+
bad-docstring-quotes:14:4:15:25:FFFF.method3:"Bad docstring quotes in method, expected """""", given '":HIGH
4+
bad-docstring-quotes:17:4:18:30:FFFF.method4:"Bad docstring quotes in method, expected """""", given '":HIGH

0 commit comments

Comments
 (0)