Skip to content

Commit fffde57

Browse files
DanielNoordPierre-Sassoulas
authored andcommitted
Format docstrings with pydocstringformatter
1 parent 15c8825 commit fffde57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+208
-264
lines changed

examples/custom.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class MyAstroidChecker(BaseChecker):
5252
def visit_call(self, node: nodes.Call) -> None:
5353
"""Called when a :class:`.nodes.Call` node is visited.
5454
55-
See :mod:`astroid` for the description of available nodes."""
55+
See :mod:`astroid` for the description of available nodes.
56+
"""
5657
if not (
5758
isinstance(node.func, nodes.Attribute)
5859
and isinstance(node.func.expr, nodes.Name)

examples/deprecation_checker.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
Example checker detecting deprecated functions/methods. Following example searches for usages of
1+
"""Example checker detecting deprecated functions/methods. Following example searches for usages of
32
deprecated function `deprecated_function` and deprecated method `MyClass.deprecated_method`
43
from module mymodule:
54

pylint/checkers/base.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@
103103
class NamingStyle:
104104
"""It may seem counterintuitive that single naming style has multiple "accepted"
105105
forms of regular expressions, but we need to special-case stuff like dunder names
106-
in method names."""
106+
in method names.
107+
"""
107108

108109
ANY: Pattern[str] = re.compile(".*")
109110
CLASS_NAME_RGX: Pattern[str] = ANY
@@ -278,8 +279,7 @@ def in_nested_list(nested_list, obj):
278279

279280

280281
def _get_break_loop_node(break_node):
281-
"""
282-
Returns the loop node that holds the break node in arguments.
282+
"""Returns the loop node that holds the break node in arguments.
283283
284284
Args:
285285
break_node (astroid.Break): the break node of interest.
@@ -300,8 +300,7 @@ def _get_break_loop_node(break_node):
300300

301301

302302
def _loop_exits_early(loop):
303-
"""
304-
Returns true if a loop may end with a break statement.
303+
"""Returns true if a loop may end with a break statement.
305304
306305
Args:
307306
loop (astroid.For, astroid.While): the loop node inspected.
@@ -389,8 +388,7 @@ def _determine_function_name_type(node: nodes.FunctionDef, config=None):
389388

390389

391390
def _has_abstract_methods(node):
392-
"""
393-
Determine if the given `node` has abstract methods.
391+
"""Determine if the given `node` has abstract methods.
394392
395393
The methods should be made abstract by decorating them
396394
with `abc` decorators.
@@ -1496,7 +1494,8 @@ def _check_not_in_finally(self, node, node_name, breaker_classes=()):
14961494
"""check that a node is not inside a 'finally' clause of a
14971495
'try...finally' statement.
14981496
If we find a parent which type is in breaker_classes before
1499-
a 'try...finally' block we skip the whole check."""
1497+
a 'try...finally' block we skip the whole check.
1498+
"""
15001499
# if self._tryfinallys is empty, we're not an in try...finally block
15011500
if not self._tryfinallys:
15021501
return

pylint/checkers/base_checker.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class BaseChecker(OptionsProviderMixIn):
5050
def __init__(self, linter=None):
5151
"""checker instances should have the linter as argument
5252
53-
:param ILinter linter: is an object implementing ILinter."""
53+
:param ILinter linter: is an object implementing ILinter.
54+
"""
5455
if self.name is not None:
5556
self.name = self.name.lower()
5657
super().__init__()
@@ -67,7 +68,8 @@ def __repr__(self):
6768

6869
def __str__(self):
6970
"""This might be incomplete because multiple class inheriting BaseChecker
70-
can have the same name. Cf MessageHandlerMixIn.get_full_documentation()"""
71+
can have the same name. Cf MessageHandlerMixIn.get_full_documentation()
72+
"""
7173
return self.get_full_documentation(
7274
msgs=self.msgs, options=self.options_and_values(), reports=self.reports
7375
)
@@ -132,7 +134,8 @@ def check_consistency(self):
132134
checker.
133135
134136
:raises InvalidMessageError: If the checker id in the messages are not
135-
always the same."""
137+
always the same.
138+
"""
136139
checker_id = None
137140
existing_ids = []
138141
for message in self.messages:

pylint/checkers/classes/class_checker.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ class _DefaultMissing:
186186

187187

188188
def _has_different_parameters_default_value(original, overridden):
189-
"""
190-
Check if original and overridden methods arguments have different default values
189+
"""Check if original and overridden methods arguments have different default values
191190
192191
Return True if one of the overridden arguments has a default
193192
value different from the default value of the original argument
@@ -821,8 +820,7 @@ def _check_consistent_mro(self, node):
821820
pass
822821

823822
def _check_proper_bases(self, node):
824-
"""
825-
Detect that a class inherits something which is not
823+
"""Detect that a class inherits something which is not
826824
a class or a type.
827825
"""
828826
for base in node.bases:
@@ -1655,9 +1653,7 @@ def _check_protected_attribute_access(self, node: nodes.Attribute):
16551653

16561654
@staticmethod
16571655
def _is_called_inside_special_method(node: nodes.NodeNG) -> bool:
1658-
"""
1659-
Returns true if the node is located inside a special (aka dunder) method
1660-
"""
1656+
"""Returns true if the node is located inside a special (aka dunder) method"""
16611657
try:
16621658
frame_name = node.frame().name
16631659
except AttributeError:

pylint/checkers/classes/special_methods_checker.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222

2323
def _safe_infer_call_result(node, caller, context=None):
24-
"""
25-
Safely infer the return value of a function.
24+
"""Safely infer the return value of a function.
2625
2726
Returns None if inference failed or if there is some ambiguity (more than
2827
one node has been inferred). Otherwise, returns inferred value.

pylint/checkers/ellipsis_checker.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""Ellipsis checker for Python code
2-
"""
1+
"""Ellipsis checker for Python code"""
32
from typing import TYPE_CHECKING
43

54
from astroid import nodes

pylint/checkers/exceptions.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ def predicate(obj):
5757

5858

5959
def _annotated_unpack_infer(stmt, context=None):
60-
"""
61-
Recursively generate nodes inferred by the given statement.
60+
"""Recursively generate nodes inferred by the given statement.
6261
If the inferred value is a list or a tuple, recurse on the elements.
6362
Returns an iterator which yields tuples in the format
6463
('original node', 'inferred node').

pylint/checkers/format.py

+9-20
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,7 @@ def _check_multi_statement_line(self, node, line):
669669
self._visited_lines[line] = 2
670670

671671
def check_line_ending(self, line: str, i: int) -> None:
672-
"""
673-
Check that the final newline is not missing and that there is no trailing whitespace.
674-
"""
672+
"""Check that the final newline is not missing and that there is no trailing whitespace."""
675673
if not line.endswith("\n"):
676674
self.add_message("missing-final-newline", line=i)
677675
return
@@ -683,9 +681,7 @@ def check_line_ending(self, line: str, i: int) -> None:
683681
)
684682

685683
def check_line_length(self, line: str, i: int, checker_off: bool) -> None:
686-
"""
687-
Check that the line length is less than the authorized value
688-
"""
684+
"""Check that the line length is less than the authorized value"""
689685
max_chars = self.config.max_line_length
690686
ignore_long_line = self.config.ignore_long_lines
691687
line = line.rstrip()
@@ -697,9 +693,7 @@ def check_line_length(self, line: str, i: int, checker_off: bool) -> None:
697693

698694
@staticmethod
699695
def remove_pylint_option_from_lines(options_pattern_obj) -> str:
700-
"""
701-
Remove the `# pylint ...` pattern from lines
702-
"""
696+
"""Remove the `# pylint ...` pattern from lines"""
703697
lines = options_pattern_obj.string
704698
purged_lines = (
705699
lines[: options_pattern_obj.start(1)].rstrip()
@@ -709,9 +703,7 @@ def remove_pylint_option_from_lines(options_pattern_obj) -> str:
709703

710704
@staticmethod
711705
def is_line_length_check_activated(pylint_pattern_match_object) -> bool:
712-
"""
713-
Return true if the line length check is activated
714-
"""
706+
"""Return true if the line length check is activated"""
715707
try:
716708
for pragma in parse_pragma(pylint_pattern_match_object.group(2)):
717709
if pragma.action == "disable" and "line-too-long" in pragma.messages:
@@ -723,9 +715,7 @@ def is_line_length_check_activated(pylint_pattern_match_object) -> bool:
723715

724716
@staticmethod
725717
def specific_splitlines(lines: str) -> List[str]:
726-
"""
727-
Split lines according to universal newlines except those in a specific sets
728-
"""
718+
"""Split lines according to universal newlines except those in a specific sets"""
729719
unsplit_ends = {
730720
"\v",
731721
"\x0b",
@@ -749,11 +739,10 @@ def specific_splitlines(lines: str) -> List[str]:
749739
return res
750740

751741
def check_lines(self, lines: str, lineno: int) -> None:
752-
"""
753-
Check lines have :
754-
- a final newline
755-
- no trailing whitespace
756-
- less than a maximum number of characters
742+
"""Check lines have :
743+
- a final newline
744+
- no trailing whitespace
745+
- less than a maximum number of characters
757746
"""
758747
# we're first going to do a rough check whether any lines in this set
759748
# go over the line limit. If none of them do, then we don't need to

pylint/checkers/logging.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2424
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
2525

26-
"""checker for use of Python logging
27-
"""
26+
"""checker for use of Python logging"""
2827
import string
2928
from typing import TYPE_CHECKING, Set
3029

@@ -295,9 +294,7 @@ def _helper_string(self, node):
295294

296295
@staticmethod
297296
def _is_operand_literal_str(operand):
298-
"""
299-
Return True if the operand in argument is a literal string
300-
"""
297+
"""Return True if the operand in argument is a literal string"""
301298
return isinstance(operand, nodes.Const) and operand.name == "str"
302299

303300
def _check_call_func(self, node: nodes.Call):

pylint/checkers/newstyle.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2121
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
2222

23-
"""check for new / old style related problems
24-
"""
23+
"""check for new / old style related problems"""
2524
from typing import TYPE_CHECKING
2625

2726
import astroid

pylint/checkers/refactoring/implicit_booleaness_checker.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ def instance_has_bool(class_def: nodes.ClassDef) -> bool:
129129
def visit_unaryop(self, node: nodes.UnaryOp) -> None:
130130
"""`not len(S)` must become `not S` regardless if the parent block
131131
is a test condition or something else (boolean expression)
132-
e.g. `if not len(S):`"""
132+
e.g. `if not len(S):`
133+
"""
133134
if (
134135
isinstance(node, nodes.UnaryOp)
135136
and node.op == "not"

pylint/checkers/refactoring/recommendation_checker.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ def visit_const(self, node: nodes.Const) -> None:
337337

338338
def _detect_replacable_format_call(self, node: nodes.Const) -> None:
339339
"""Check whether a string is used in a call to format() or '%' and whether it
340-
can be replaced by an f-string"""
340+
can be replaced by an f-string
341+
"""
341342
if (
342343
isinstance(node.parent, nodes.Attribute)
343344
and node.parent.attrname == "format"

pylint/checkers/refactoring/refactoring_checker.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ def _is_a_return_statement(node: nodes.Call) -> bool:
118118

119119

120120
def _is_part_of_with_items(node: nodes.Call) -> bool:
121-
"""
122-
Checks if one of the node's parents is a ``nodes.With`` node and that the node itself is located
121+
"""Checks if one of the node's parents is a ``nodes.With`` node and that the node itself is located
123122
somewhere under its ``items``.
124123
"""
125124
frame = node.frame()
@@ -135,7 +134,8 @@ def _is_part_of_with_items(node: nodes.Call) -> bool:
135134

136135
def _will_be_released_automatically(node: nodes.Call) -> bool:
137136
"""Checks if a call that could be used in a ``with`` statement is used in an alternative
138-
construct which would ensure that its __exit__ method is called."""
137+
construct which would ensure that its __exit__ method is called.
138+
"""
139139
callables_taking_care_of_exit = frozenset(
140140
(
141141
"contextlib._BaseExitStack.enter_context",
@@ -152,7 +152,8 @@ def _will_be_released_automatically(node: nodes.Call) -> bool:
152152

153153
class ConsiderUsingWithStack(NamedTuple):
154154
"""Stack for objects that may potentially trigger a R1732 message
155-
if they are not used in a ``with`` block later on."""
155+
if they are not used in a ``with`` block later on.
156+
"""
156157

157158
module_scope: Dict[str, nodes.NodeNG] = {}
158159
class_scope: Dict[str, nodes.NodeNG] = {}
@@ -1278,7 +1279,8 @@ def _apply_boolean_simplification_rules(operator, values):
12781279
reverse for AND
12791280
12801281
2) False values in OR expressions are only relevant if all values are
1281-
false, and the reverse for AND"""
1282+
false, and the reverse for AND
1283+
"""
12821284
simplified_values = []
12831285

12841286
for subnode in values:
@@ -1299,7 +1301,8 @@ def _simplify_boolean_operation(self, bool_op):
12991301
"""Attempts to simplify a boolean operation
13001302
13011303
Recursively applies simplification on the operator terms,
1302-
and keeps track of whether reductions have been made."""
1304+
and keeps track of whether reductions have been made.
1305+
"""
13031306
children = list(bool_op.get_children())
13041307
intermediate = [
13051308
self._simplify_boolean_operation(child)
@@ -1320,7 +1323,8 @@ def _check_simplifiable_condition(self, node):
13201323
"""Check if a boolean condition can be simplified.
13211324
13221325
Variables will not be simplified, even in the value can be inferred,
1323-
and expressions like '3 + 4' will remain expanded."""
1326+
and expressions like '3 + 4' will remain expanded.
1327+
"""
13241328
if not utils.is_test_condition(node):
13251329
return
13261330

@@ -1506,8 +1510,7 @@ def _check_use_list_or_dict_literal(self, node: nodes.Call) -> None:
15061510
self.add_message("use-dict-literal", node=node)
15071511

15081512
def _check_consider_using_join(self, aug_assign):
1509-
"""
1510-
We start with the augmented assignment and work our way upwards.
1513+
"""We start with the augmented assignment and work our way upwards.
15111514
Names of variables for nodes if match successful:
15121515
result = '' # assign
15131516
for number in ['1', '2', '3'] # for_loop
@@ -1630,8 +1633,7 @@ def _check_unnecessary_comprehension(self, node: nodes.Comprehension) -> None:
16301633

16311634
@staticmethod
16321635
def _is_and_or_ternary(node):
1633-
"""
1634-
Returns true if node is 'condition and true_value or false_value' form.
1636+
"""Returns true if node is 'condition and true_value or false_value' form.
16351637
16361638
All of: condition, true_value and false_value should not be a complex boolean expression
16371639
"""
@@ -1793,9 +1795,7 @@ def _is_node_return_ended(self, node: nodes.NodeNG) -> bool:
17931795

17941796
@staticmethod
17951797
def _has_return_in_siblings(node: nodes.NodeNG) -> bool:
1796-
"""
1797-
Returns True if there is at least one return in the node's siblings
1798-
"""
1798+
"""Returns True if there is at least one return in the node's siblings"""
17991799
next_sibling = node.next_sibling()
18001800
while next_sibling:
18011801
if isinstance(next_sibling, nodes.Return):

0 commit comments

Comments
 (0)