Skip to content

Commit 0369668

Browse files
[pydoclint] Implement docstring-extraneous-parameter (DOC102) (#20376)
## Summary Implement `docstring-extraneous-parameter` (`DOC102`). This rule checks that all parameters present in a functions docstring are also present in its signature. Split from #13280, per this [comment](#13280 (comment)). Part of #12434. ## Test Plan Test cases added. --------- Co-authored-by: Brent Westbrook <[email protected]>
1 parent 058fc37 commit 0369668

File tree

9 files changed

+1285
-15
lines changed

9 files changed

+1285
-15
lines changed
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
# DOC102
2+
def add_numbers(b):
3+
"""
4+
Adds two numbers and returns the result.
5+
6+
Args:
7+
a (int): The first number to add.
8+
b (int): The second number to add.
9+
10+
Returns:
11+
int: The sum of the two numbers.
12+
"""
13+
return a + b
14+
15+
16+
# DOC102
17+
def multiply_list_elements(lst):
18+
"""
19+
Multiplies each element in a list by a given multiplier.
20+
21+
Args:
22+
lst (list of int): A list of integers.
23+
multiplier (int): The multiplier for each element in the list.
24+
25+
Returns:
26+
list of int: A new list with each element multiplied.
27+
"""
28+
return [x * multiplier for x in lst]
29+
30+
31+
# DOC102
32+
def find_max_value():
33+
"""
34+
Finds the maximum value in a list of numbers.
35+
36+
Args:
37+
numbers (list of int): A list of integers to search through.
38+
39+
Returns:
40+
int: The maximum value found in the list.
41+
"""
42+
return max(numbers)
43+
44+
45+
# DOC102
46+
def create_user_profile(location="here"):
47+
"""
48+
Creates a user profile with basic information.
49+
50+
Args:
51+
name (str): The name of the user.
52+
age (int): The age of the user.
53+
email (str): The user's email address.
54+
location (str): The location of the user.
55+
56+
Returns:
57+
dict: A dictionary containing the user's profile.
58+
"""
59+
return {
60+
'name': name,
61+
'age': age,
62+
'email': email,
63+
'location': location
64+
}
65+
66+
67+
# DOC102
68+
def calculate_total_price(item_prices, discount):
69+
"""
70+
Calculates the total price after applying tax and a discount.
71+
72+
Args:
73+
item_prices (list of float): A list of prices for each item.
74+
tax_rate (float): The tax rate to apply.
75+
discount (float): The discount to subtract from the total.
76+
77+
Returns:
78+
float: The final total price after tax and discount.
79+
"""
80+
total = sum(item_prices)
81+
total_with_tax = total + (total * tax_rate)
82+
final_total = total_with_tax - discount
83+
return final_total
84+
85+
86+
# DOC102
87+
def send_email(subject, body, bcc_address=None):
88+
"""
89+
Sends an email to the specified recipients.
90+
91+
Args:
92+
subject (str): The subject of the email.
93+
body (str): The content of the email.
94+
to_address (str): The recipient's email address.
95+
cc_address (str, optional): The email address for CC. Defaults to None.
96+
bcc_address (str, optional): The email address for BCC. Defaults to None.
97+
98+
Returns:
99+
bool: True if the email was sent successfully, False otherwise.
100+
"""
101+
return True
102+
103+
104+
# DOC102
105+
def concatenate_strings(*args):
106+
"""
107+
Concatenates multiple strings with a specified separator.
108+
109+
Args:
110+
separator (str): The separator to use between strings.
111+
*args (str): Variable length argument list of strings to concatenate.
112+
113+
Returns:
114+
str: A single concatenated string.
115+
"""
116+
return separator.join(args)
117+
118+
119+
# DOC102
120+
def process_order(order_id):
121+
"""
122+
Processes an order with a list of items and optional order details.
123+
124+
Args:
125+
order_id (int): The unique identifier for the order.
126+
*items (str): Variable length argument list of items in the order.
127+
**details (dict): Additional details such as shipping method and address.
128+
129+
Returns:
130+
dict: A dictionary containing the order summary.
131+
"""
132+
return {
133+
'order_id': order_id,
134+
'items': items,
135+
'details': details
136+
}
137+
138+
139+
class Calculator:
140+
"""
141+
A simple calculator class that can perform basic arithmetic operations.
142+
"""
143+
144+
# DOC102
145+
def __init__(self):
146+
"""
147+
Initializes the calculator with an initial value.
148+
149+
Args:
150+
value (int, optional): The initial value of the calculator. Defaults to 0.
151+
"""
152+
self.value = value
153+
154+
# DOC102
155+
def add(self, number2):
156+
"""
157+
Adds a number to the current value.
158+
159+
Args:
160+
number (int or float): The number to add to the current value.
161+
162+
Returns:
163+
int or float: The updated value after addition.
164+
"""
165+
self.value += number + number2
166+
return self.value
167+
168+
# DOC102
169+
@classmethod
170+
def from_string(cls):
171+
"""
172+
Creates a Calculator instance from a string representation of a number.
173+
174+
Args:
175+
value_str (str): The string representing the initial value.
176+
177+
Returns:
178+
Calculator: A new instance of Calculator initialized with the value from the string.
179+
"""
180+
value = float(value_str)
181+
return cls(value)
182+
183+
# DOC102
184+
@staticmethod
185+
def is_valid_number():
186+
"""
187+
Checks if a given number is valid (int or float).
188+
189+
Args:
190+
number (any): The value to check.
191+
192+
Returns:
193+
bool: True if the number is valid, False otherwise.
194+
"""
195+
return isinstance(number, (int, float))
196+
197+
# OK
198+
def foo(param1, param2, *args, **kwargs):
199+
"""Foo.
200+
201+
Args:
202+
param1 (int): The first parameter.
203+
param2 (:obj:`str`, optional): The second parameter. Defaults to None.
204+
Second line of description: should be indented.
205+
*args: Variable length argument list.
206+
**kwargs: Arbitrary keyword arguments.
207+
"""
208+
return
209+
210+
# OK
211+
def on_server_unloaded(self, server_context: ServerContext) -> None:
212+
''' Execute ``on_server_unloaded`` from ``server_lifecycle.py`` (if
213+
it is defined) when the server cleanly exits. (Before stopping the
214+
server's ``IOLoop``.)
215+
216+
Args:
217+
server_context (ServerContext) :
218+
219+
.. warning::
220+
In practice this code may not run, since servers are often killed
221+
by a signal.
222+
223+
224+
'''
225+
return self._lifecycle_handler.on_server_unloaded(server_context)
226+
227+
# OK
228+
def function_with_kwargs(param1, param2, **kwargs):
229+
"""Function with **kwargs parameter.
230+
231+
Args:
232+
param1 (int): The first parameter.
233+
param2 (str): The second parameter.
234+
extra_param (str): An extra parameter that may be passed via **kwargs.
235+
another_extra (int): Another extra parameter.
236+
"""
237+
return
238+
239+
# OK
240+
def add_numbers(b):
241+
"""
242+
Adds two numbers and returns the result.
243+
244+
Args:
245+
b: The second number to add.
246+
247+
Returns:
248+
int: The sum of the two numbers.
249+
"""
250+
return
251+
252+
# DOC102
253+
def add_numbers(b):
254+
"""
255+
Adds two numbers and returns the result.
256+
257+
Args:
258+
a: The first number to add.
259+
b: The second number to add.
260+
261+
Returns:
262+
int: The sum of the two numbers.
263+
"""
264+
return a + b

0 commit comments

Comments
 (0)