@@ -521,6 +521,9 @@ def check_imperative_mood(self, function, docstring): # def context
521
521
"Returns the pathname ...".
522
522
523
523
"""
524
+ ctxs = list (self ._get_section_contexts_autodetect (docstring ))
525
+ if ctxs and ctxs [0 ].is_docstring_start :
526
+ return
524
527
if (
525
528
docstring
526
529
and not function .is_test
@@ -604,6 +607,16 @@ def check_starts_with_this(self, function, docstring):
604
607
if first_word .lower () == 'this' :
605
608
return violations .D404 ()
606
609
610
+ @staticmethod
611
+ def _is_at_docstring_start (context ):
612
+ """Return whether a `SectionContext` occurs at the start of a docstring."""
613
+ return context .original_index == 1 and context .previous_line in [
614
+ '"' ,
615
+ "'" ,
616
+ '"""' ,
617
+ "'''" ,
618
+ ]
619
+
607
620
@staticmethod
608
621
def _is_docstring_section (context ):
609
622
"""Check if the suspected context is really a section header.
@@ -656,7 +669,9 @@ def _is_docstring_section(context):
656
669
)
657
670
658
671
prev_line_looks_like_end_of_paragraph = (
659
- prev_line_ends_with_punctuation or is_blank (context .previous_line )
672
+ prev_line_ends_with_punctuation
673
+ or is_blank (context .previous_line )
674
+ or context .is_docstring_start
660
675
)
661
676
662
677
return (
@@ -766,7 +781,10 @@ def _check_common_section(
766
781
else :
767
782
yield violations .D410 (capitalized_section )
768
783
769
- if not is_blank (context .previous_line ):
784
+ if (
785
+ not is_blank (context .previous_line )
786
+ and not context .is_docstring_start
787
+ ):
770
788
yield violations .D411 (capitalized_section )
771
789
772
790
yield from cls ._check_blanks_and_section_underline (
@@ -1004,6 +1022,7 @@ def _suspected_as_section(_line):
1004
1022
'line' ,
1005
1023
'following_lines' ,
1006
1024
'original_index' ,
1025
+ 'is_docstring_start' ,
1007
1026
'is_last_section' ,
1008
1027
),
1009
1028
)
@@ -1019,15 +1038,18 @@ def _suspected_as_section(_line):
1019
1038
lines [i + 1 :],
1020
1039
i ,
1021
1040
False ,
1041
+ False ,
1022
1042
)
1023
1043
for i in suspected_section_indices
1024
1044
)
1025
-
1026
- # Now that we have manageable objects - rule out false positives.
1027
1045
contexts = (
1028
- c for c in contexts if ConventionChecker ._is_docstring_section (c )
1046
+ c ._replace (is_docstring_start = cls ._is_at_docstring_start (c ))
1047
+ for c in contexts
1029
1048
)
1030
1049
1050
+ # Now that we have manageable objects - rule out false positives.
1051
+ contexts = (c for c in contexts if cls ._is_docstring_section (c ))
1052
+
1031
1053
# Now we shall trim the `following lines` field to only reach the
1032
1054
# next section name.
1033
1055
for a , b in pairwise (contexts , None ):
@@ -1039,6 +1061,7 @@ def _suspected_as_section(_line):
1039
1061
a .line ,
1040
1062
lines [a .original_index + 1 : end ],
1041
1063
a .original_index ,
1064
+ a .is_docstring_start ,
1042
1065
b is None ,
1043
1066
)
1044
1067
0 commit comments