Skip to content

Commit 05440f1

Browse files
Rebased semi-manual changes on #5787
1 parent 595ec42 commit 05440f1

Some content is hidden

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

58 files changed

+234
-190
lines changed

doc/exts/pylint_extensions.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
33
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
44

5-
"""Script used to generate the extensions file before building the actual documentation."""
5+
"""Script used to generate the extensions file before building the actual
6+
documentation.
7+
"""
68

79
import os
810
import re

doc/exts/pylint_features.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
33
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
44

5-
"""Script used to generate the features file before building the actual documentation."""
5+
"""Script used to generate the features file before building the actual
6+
documentation.
7+
"""
68

79
import os
810

doc/user_guide/message-control.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Here's an example with all these rules in a single place:
112112
pass
113113

114114
def meth1(self, arg):
115-
"""this issues a message"""
115+
"""This issues a message"""
116116
print(self)
117117

118118
def meth2(self, arg):
@@ -122,14 +122,14 @@ Here's an example with all these rules in a single place:
122122
+ "foo")
123123

124124
def meth3(self):
125-
"""test one line disabling"""
125+
"""Test one line disabling"""
126126
# no error
127127
print(self.bla) # pylint: disable=no-member
128128
# error
129129
print(self.blop)
130130

131131
def meth4(self):
132-
"""test re-enabling"""
132+
"""Test re-enabling"""
133133
# pylint: disable=no-member
134134
# no error
135135
print(self.bla)
@@ -139,7 +139,7 @@ Here's an example with all these rules in a single place:
139139
print(self.blip)
140140

141141
def meth5(self):
142-
"""test IF sub-block re-enabling"""
142+
"""Test IF sub-block re-enabling"""
143143
# pylint: disable=no-member
144144
# no error
145145
print(self.bla)
@@ -154,7 +154,7 @@ Here's an example with all these rules in a single place:
154154
print(self.blip)
155155

156156
def meth6(self):
157-
"""test TRY/EXCEPT sub-block re-enabling"""
157+
"""Test TRY/EXCEPT sub-block re-enabling"""
158158
# pylint: disable=no-member
159159
# no error
160160
print(self.bla)
@@ -169,7 +169,7 @@ Here's an example with all these rules in a single place:
169169
print(self.blip)
170170

171171
def meth7(self):
172-
"""test one line block opening disabling"""
172+
"""Test one line block opening disabling"""
173173
if self.blop: # pylint: disable=no-member
174174
# error
175175
print(self.blip)
@@ -180,7 +180,7 @@ Here's an example with all these rules in a single place:
180180
print(self.blip)
181181

182182
def meth8(self):
183-
"""test late disabling"""
183+
"""Test late disabling"""
184184
# error
185185
print(self.blip)
186186
# pylint: disable=no-member
@@ -189,7 +189,7 @@ Here's an example with all these rules in a single place:
189189
print(self.blop)
190190

191191
def meth9(self):
192-
"""test next line disabling"""
192+
"""Test next line disabling"""
193193
# no error
194194
# pylint: disable-next=no-member
195195
print(self.bla)

examples/deprecation_checker.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
"""Example checker detecting deprecated functions/methods. Following example searches for usages of
2-
deprecated function `deprecated_function` and deprecated method `MyClass.deprecated_method`
3-
from module mymodule:
1+
"""Example checker detecting deprecated functions/methods. Following example searches
2+
for usages of deprecated function `deprecated_function` and deprecated method
3+
`MyClass.deprecated_method` from module mymodule:
44
55
.. code-block:: console
66
$ cat mymodule.py
@@ -59,7 +59,8 @@ class DeprecationChecker(DeprecatedMixin, BaseChecker):
5959
name = "deprecated"
6060

6161
def deprecated_methods(self) -> Set[str]:
62-
"""Callback method called by DeprecatedMixin for every method/function found in the code.
62+
"""Callback method called by DeprecatedMixin for every method/function found in
63+
the code.
6364
6465
Returns:
6566
collections.abc.Container of deprecated function/method names.

pylint/checkers/classes/special_methods_checker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
def _safe_infer_call_result(node, caller, context=None):
2424
"""Safely infer the return value of a function.
2525
26-
Returns None if inference failed or if there is some ambiguity (more than
27-
one node has been inferred). Otherwise, returns inferred value.
26+
Returns None if inference failed or if there is some ambiguity (more than one node
27+
has been inferred). Otherwise, returns inferred value.
2828
"""
2929
try:
3030
inferit = node.infer_call_result(caller, context=context)

pylint/checkers/refactoring/implicit_booleaness_checker.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ def instance_has_bool(class_def: nodes.ClassDef) -> bool:
127127

128128
@utils.check_messages("use-implicit-booleaness-not-len")
129129
def visit_unaryop(self, node: nodes.UnaryOp) -> None:
130-
"""`not len(S)` must become `not S` regardless if the parent block
131-
is a test condition or something else (boolean expression)
132-
e.g. `if not len(S):`
130+
"""`not len(S)` must become `not S` regardless if the parent block is a test
131+
condition or something else (boolean expression) e.g. `if not len(S):`
133132
"""
134133
if (
135134
isinstance(node, nodes.UnaryOp)

pylint/checkers/refactoring/recommendation_checker.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ def _check_consider_iterating_dictionary(self, node: nodes.Call) -> None:
102102
self.add_message("consider-iterating-dictionary", node=node)
103103

104104
def _check_use_maxsplit_arg(self, node: nodes.Call) -> None:
105-
"""Add message when accessing first or last elements of a str.split() or str.rsplit()."""
105+
"""Add message when accessing first or last elements of a str.split() or
106+
str.rsplit().
107+
"""
106108

107109
# Check if call is split() or rsplit()
108110
if not (
@@ -337,7 +339,7 @@ def visit_const(self, node: nodes.Const) -> None:
337339

338340
def _detect_replacable_format_call(self, node: nodes.Const) -> None:
339341
"""Check whether a string is used in a call to format() or '%' and whether it
340-
can be replaced by an f-string
342+
can be replaced by an f-string.
341343
"""
342344
if (
343345
isinstance(node.parent, nodes.Attribute)

pylint/checkers/refactoring/refactoring_checker.py

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

119119

120120
def _is_part_of_with_items(node: nodes.Call) -> bool:
121-
"""Checks if one of the node's parents is a ``nodes.With`` node and that the node itself is located
122-
somewhere under its ``items``.
121+
"""Checks if one of the node's parents is a ``nodes.With`` node and that the node
122+
itself is located somewhere under its ``items``.
123123
"""
124124
frame = node.frame(future=True)
125125
current = node
@@ -133,8 +133,8 @@ def _is_part_of_with_items(node: nodes.Call) -> bool:
133133

134134

135135
def _will_be_released_automatically(node: nodes.Call) -> bool:
136-
"""Checks if a call that could be used in a ``with`` statement is used in an alternative
137-
construct which would ensure that its __exit__ method is called.
136+
"""Checks if a call that could be used in a ``with`` statement is used in an
137+
alternative construct which would ensure that its __exit__ method is called.
138138
"""
139139
callables_taking_care_of_exit = frozenset(
140140
(
@@ -151,8 +151,8 @@ def _will_be_released_automatically(node: nodes.Call) -> bool:
151151

152152

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

158158
module_scope: Dict[str, nodes.NodeNG] = {}
@@ -181,9 +181,9 @@ def clear_all(self) -> None:
181181
class RefactoringChecker(checkers.BaseTokenChecker):
182182
"""Looks for code which can be refactored.
183183
184-
This checker also mixes the astroid and the token approaches
185-
in order to create knowledge about whether an "else if" node
186-
is a true "else if" node, or an "elif" node.
184+
This checker also mixes the astroid and the token approaches in order to create
185+
knowledge about whether an "else if" node is a true "else if" node, or an "elif"
186+
node.
187187
"""
188188

189189
__implements__ = (interfaces.ITokenChecker, interfaces.IAstroidChecker)
@@ -488,10 +488,9 @@ def _is_bool_const(node):
488488
def _is_actual_elif(self, node):
489489
"""Check if the given node is an actual elif.
490490
491-
This is a problem we're having with the builtin ast module,
492-
which splits `elif` branches into a separate if statement.
493-
Unfortunately we need to know the exact type in certain
494-
cases.
491+
This is a problem we're having with the builtin ast module, which splits `elif`
492+
branches into a separate if statement. Unfortunately we need to know the exact
493+
type in certain cases.
495494
"""
496495
if isinstance(node.parent, nodes.If):
497496
orelse = node.parent.orelse
@@ -504,11 +503,10 @@ def _is_actual_elif(self, node):
504503
def _check_simplifiable_if(self, node):
505504
"""Check if the given if node can be simplified.
506505
507-
The if statement can be reduced to a boolean expression
508-
in some cases. For instance, if there are two branches
509-
and both of them return a boolean value that depends on
510-
the result of the statement's test, then this can be reduced
511-
to `bool(test)` without losing any functionality.
506+
The if statement can be reduced to a boolean expression in some cases. For
507+
instance, if there are two branches and both of them return a boolean value that
508+
depends on the result of the statement's test, then this can be reduced to
509+
`bool(test)` without losing any functionality.
512510
"""
513511

514512
if self._is_actual_elif(node):
@@ -1301,8 +1299,8 @@ def _apply_boolean_simplification_rules(operator, values):
13011299
def _simplify_boolean_operation(self, bool_op):
13021300
"""Attempts to simplify a boolean operation.
13031301
1304-
Recursively applies simplification on the operator terms,
1305-
and keeps track of whether reductions have been made.
1302+
Recursively applies simplification on the operator terms, and keeps track of
1303+
whether reductions have been made.
13061304
"""
13071305
children = list(bool_op.get_children())
13081306
intermediate = [
@@ -1323,8 +1321,8 @@ def _simplify_boolean_operation(self, bool_op):
13231321
def _check_simplifiable_condition(self, node):
13241322
"""Check if a boolean condition can be simplified.
13251323
1326-
Variables will not be simplified, even in the value can be inferred,
1327-
and expressions like '3 + 4' will remain expanded.
1324+
Variables will not be simplified, even in the value can be inferred, and
1325+
expressions like '3 + 4' will remain expanded.
13281326
"""
13291327
if not utils.is_test_condition(node):
13301328
return
@@ -1503,7 +1501,7 @@ def _check_consider_using_with(self, node: nodes.Call):
15031501
self.add_message("consider-using-with", node=node)
15041502

15051503
def _check_use_list_or_dict_literal(self, node: nodes.Call) -> None:
1506-
"""Check if empty list or dict is created by using the literal [] or {}."""
1504+
"""Check if empty list or dict is created by using '[]' or '{}'."""
15071505
if node.as_string() in {"list()", "dict()"}:
15081506
inferred = utils.safe_infer(node.func)
15091507
if isinstance(inferred, nodes.ClassDef) and not node.args:
@@ -1514,6 +1512,7 @@ def _check_use_list_or_dict_literal(self, node: nodes.Call) -> None:
15141512

15151513
def _check_consider_using_join(self, aug_assign):
15161514
"""We start with the augmented assignment and work our way upwards.
1515+
15171516
Names of variables for nodes if match successful:
15181517
result = '' # assign
15191518
for number in ['1', '2', '3'] # for_loop
@@ -1638,7 +1637,8 @@ def _check_unnecessary_comprehension(self, node: nodes.Comprehension) -> None:
16381637
def _is_and_or_ternary(node):
16391638
"""Returns true if node is 'condition and true_value or false_value' form.
16401639
1641-
All of: condition, true_value and false_value should not be a complex boolean expression
1640+
All of: condition, true_value and false_value should not be a complex boolean
1641+
expression
16421642
"""
16431643
return (
16441644
isinstance(node, nodes.BoolOp)
@@ -1671,7 +1671,6 @@ def _check_consistent_returns(self, node: nodes.FunctionDef) -> None:
16711671
16721672
Args:
16731673
node (nodes.FunctionDef): the function holding the return statements.
1674-
16751674
"""
16761675
# explicit return statements are those with a not None value
16771676
explicit_returns = [
@@ -1756,7 +1755,6 @@ def _is_node_return_ended(self, node: nodes.NodeNG) -> bool:
17561755
17571756
Returns:
17581757
bool: True if the node ends with an explicit statement, False otherwise.
1759-
17601758
"""
17611759
# Recursion base case
17621760
if isinstance(node, nodes.Return):
@@ -1828,9 +1826,9 @@ def _is_function_def_never_returning(self, node: nodes.FunctionDef) -> bool:
18281826
return False
18291827

18301828
def _check_return_at_the_end(self, node):
1831-
"""Check for presence of a *single* return statement at the end of a
1832-
function. "return" or "return None" are useless because None is the
1833-
default return type if they are missing.
1829+
"""Check for presence of a *single* return statement at the end of a function.
1830+
"return" or "return None" are useless because None is the default return type if
1831+
they are missing.
18341832
18351833
NOTE: produces a message only if there is a single return statement
18361834
in the function body. Otherwise _check_consistent_returns() is called!

pylint/checkers/stdlib.py

+1
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ def _check_redundant_assert(self, node, infer):
625625

626626
def _check_datetime(self, node):
627627
"""Check that a datetime was inferred.
628+
628629
If so, emit boolean-datetime warning.
629630
"""
630631
try:

pylint/checkers/strings.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@
226226

227227

228228
def get_access_path(key, parts):
229-
"""Given a list of format specifiers, returns
230-
the final access path (e.g. a.b.c[0][1]).
229+
"""Given a list of format specifiers, returns the final access path (e.g.
230+
a.b.c[0][1]).
231231
"""
232232
path = []
233233
for is_attribute, specifier in parts:
@@ -256,8 +256,8 @@ def arg_matches_format_type(arg_type, format_type):
256256

257257

258258
class StringFormatChecker(BaseChecker):
259-
"""Checks string formatting operations to ensure that the format string
260-
is valid and the arguments match the format string.
259+
"""Checks string formatting operations to ensure that the format string is valid and
260+
the arguments match the format string.
261261
"""
262262

263263
__implements__ = (IAstroidChecker,)
@@ -539,8 +539,8 @@ def _check_new_format(self, node, func):
539539
self._check_new_format_specifiers(node, fields, named_arguments)
540540

541541
def _check_new_format_specifiers(self, node, fields, named):
542-
"""Check attribute and index access in the format
543-
string ("{0.a}" and "{0[a]}").
542+
"""Check attribute and index access in the format string ("{0.a}" and
543+
"{0[a]}").
544544
"""
545545
for key, specifiers in fields:
546546
# Obtain the argument. If it can't be obtained
@@ -933,6 +933,7 @@ def register(linter: "PyLinter") -> None:
933933

934934
def str_eval(token):
935935
"""Mostly replicate `ast.literal_eval(token)` manually to avoid any performance hit.
936+
936937
This supports f-strings, contrary to `ast.literal_eval`.
937938
We have to support all string literal notations:
938939
https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals

pylint/checkers/typecheck.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,9 @@ def visit_assign(self, node: nodes.Assign) -> None:
11421142
self._check_dundername_is_string(node)
11431143

11441144
def _check_assignment_from_function_call(self, node: nodes.Assign) -> None:
1145-
"""When assigning to a function call, check that the function returns a valid value."""
1145+
"""Check that if assigning to a function call, the function is
1146+
possibly returning something valuable
1147+
"""
11461148
if not isinstance(node.value, nodes.Call):
11471149
return
11481150

0 commit comments

Comments
 (0)