@@ -137,15 +137,43 @@ def check_docstring_formatting(docstring):
137137 prev_indent = len (prev_line ) - len (prev_line .lstrip ())
138138 is_indented_continuation = current_indent > prev_indent
139139
140- # Special case: >>> code blocks can have output lines between prompts
141- # If current line is >>> and previous line has same or greater indent (but isn't also >>>),
142- # it's likely output from previous command
143- is_code_output = (description == 'code block' and
144- prev_indent >= 0 and
145- not prev_line .strip ().startswith ('>>>' ) and
146- not prev_line .strip ().startswith ('...' ))
147-
148- if not is_prev_list and not is_sphinx_field and not is_indented_continuation and not is_code_output :
140+ # Special case for code blocks (>>>):
141+ if description == 'code block' :
142+ # In Python interactive sessions, >>> prompts after output or continuations are normal
143+ # Skip if: previous line is >>> or ..., OR both lines are indented (in code example)
144+ if (prev_line .strip ().startswith ('...' ) or
145+ prev_line .strip ().startswith ('>>>' ) or
146+ (prev_indent > 0 )): # Both lines indented = inside code example
147+ # Don't report this as an issue
148+ break
149+
150+ # Special case for bullet/numbered lists:
151+ # 1. Check if we're continuing a list (prev line is wrapped text from previous bullet)
152+ # 2. Check if we're nested under another list item
153+ is_nested_list = False
154+ if description in ['bullet list item' , 'numbered list item' ]:
155+ # Look back to find context - skip blank lines
156+ for j in range (i - 1 , max (0 , i - 10 ), - 1 ):
157+ check_line = lines [j ]
158+ if not check_line .strip ():
159+ continue # Skip blank lines
160+ check_indent = len (check_line ) - len (check_line .lstrip ())
161+
162+ # If we find a line at same indent that's also a list item, we're continuing a list
163+ if check_indent == current_indent and any (re .match (p [0 ], check_line ) for p in patterns ):
164+ is_nested_list = True # This is a list continuation
165+ break
166+
167+ # If we find a less-indented line that's also a list item, we're nested
168+ if check_indent < current_indent and any (re .match (p [0 ], check_line ) for p in patterns ):
169+ is_nested_list = True
170+ break
171+
172+ # If we find a non-list line at current or less indent (intro text), stop looking
173+ if check_indent <= current_indent :
174+ break
175+
176+ if not is_prev_list and not is_sphinx_field and not is_indented_continuation and not is_nested_list :
149177 issues .append ((i + 1 , f"{ description } without blank line before it" ))
150178 break # Only report one issue per line
151179
0 commit comments