1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
"""Module-level docstring using triple double quotes.
This is the first docstring in the file and should be treated as module documentation.
It spans multiple lines and describes the module's purpose.
This module contains comprehensive examples of all Python docstring patterns
to test and validate the enhanced docstring extraction capabilities.
"""
# Standard library imports (no docstrings)
# Module-level constant with trailing docstring
= 42
"""Documentation for a module-level constant.
This trailing docstring should be associated with MODULE_CONSTANT.
"""
# Global variable with documentation
: =
"""Global variable documentation using triple double quotes."""
=
'''Global variable documentation using triple single quotes.
Should handle both """ and ''' .
'''
def function_with_docstring():
"""Standard function docstring.
This is a function with proper docstring formatting.
Should be extracted correctly (existing functionality).
Returns:
None: This function doesn't return anything.
"""
pass
def function_with_single_quotes():
''' .
is \n and other escapes.
.
"""
pass
@property
def decorated_function():
"""
-
"""
return "example"
@staticmethod
@classmethod
def multiple_decorators():
"""
"""
pass
def function_no_docstring():
# Regular comment, not a docstring
return "no docs"
class StandardClass:
""" .
.
"""
def __init__(self, value: int):
""" .
.
:
:
"""
self.value = value
def instance_method(self):
""" .
.
is .
"""
return self.value
def instance_method_single_quotes(self):
'''Instance method with single quote docstring.
Should handle both """ and
return * 2
"""Class method docstring.
This decorated method should have its docstring extracted.
"""
return
"""Static method docstring.
This static method should have its docstring extracted.
"""
return
"""Property docstring.
This property should have its docstring extracted.
Properties are methods with special decorators.
"""
return
"""Property setter docstring.
Setter methods should also have docstring extraction.
"""
=
# Regular comment, not a docstring
return
'''Class docstring using triple single quotes.
Should handle both """ and '''
'''
def method_in_single_quote_class(self):
"""Method in class with single quote class docstring.
Mixed quote usage should work correctly.
"""
pass
class EmptyClass:
"""Empty class with only docstring."""
pass
class ClassNoDocstring:
# Regular comment, not a docstring
pass
# Nested class example
class OuterClass:
"""Outer class docstring."""
def outer_method(self):
"""Outer method docstring."""
pass
class InnerClass:
"""Inner class docstring.
Nested classes should have their docstrings extracted.
"""
def inner_method(self):
"""Inner method docstring.
Methods in nested classes should be handled.
"""
pass
# Function with complex signature
def complex_function(
param1: str,
param2: Optional[int] = None,
*args: Union[str, int],
**kwargs: Dict[str, any]
) -> List[str]:
"""Function with complex signature and docstring.
This function has a complex signature with type hints,
default values, *args, and **kwargs.
Args:
param1: A string parameter.
param2: An optional integer parameter.
*args: Variable positional arguments.
**kwargs: Variable keyword arguments.
Returns:
A list of strings.
Raises:
ValueError: If param1 is empty.
"""
if not param1:
raise ValueError("param1 cannot be empty")
return [param1] + [str(arg) for arg in args]
# Edge cases and special patterns
def function_with_immediate_docstring():"""Docstring immediately after colon."""
pass
def function_with_comment_before_docstring():
# This is a regular comment
"""This docstring comes after a comment.
Should still be extracted as the first string literal.
"""
pass
# Module-level nested function
def outer_function():
"""Outer function docstring."""
def inner_function():
"""Inner function docstring.
Nested functions should have docstring extraction.
"""
return "inner"
return inner_function
# Variable annotations with docstrings
annotated_var: int = 100
"""Documentation for an annotated variable."""
# Multiple assignment (edge case)
a, b, c = 1, 2, 3
"""Documentation for multiple assignment.
This might be an edge case that's tricky to handle.
"""
if __name__ == "__main__":
"""This is not a proper docstring location.
This should not be extracted as a docstring since it's
inside a conditional block.
"""
print("Running comprehensive docstring examples")
# File ends with a docstring (edge case)
def final_function():
"""Final function in the file.
This tests that docstring extraction works for the last function.
"""
return "final"