@@ -118,8 +118,8 @@ def _is_a_return_statement(node: nodes.Call) -> bool:
118
118
119
119
120
120
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``.
123
123
"""
124
124
frame = node .frame (future = True )
125
125
current = node
@@ -133,8 +133,8 @@ def _is_part_of_with_items(node: nodes.Call) -> bool:
133
133
134
134
135
135
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.
138
138
"""
139
139
callables_taking_care_of_exit = frozenset (
140
140
(
@@ -151,8 +151,8 @@ def _will_be_released_automatically(node: nodes.Call) -> bool:
151
151
152
152
153
153
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.
156
156
"""
157
157
158
158
module_scope : Dict [str , nodes .NodeNG ] = {}
@@ -181,9 +181,9 @@ def clear_all(self) -> None:
181
181
class RefactoringChecker (checkers .BaseTokenChecker ):
182
182
"""Looks for code which can be refactored.
183
183
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.
187
187
"""
188
188
189
189
__implements__ = (interfaces .ITokenChecker , interfaces .IAstroidChecker )
@@ -488,10 +488,9 @@ def _is_bool_const(node):
488
488
def _is_actual_elif (self , node ):
489
489
"""Check if the given node is an actual elif.
490
490
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.
495
494
"""
496
495
if isinstance (node .parent , nodes .If ):
497
496
orelse = node .parent .orelse
@@ -504,11 +503,10 @@ def _is_actual_elif(self, node):
504
503
def _check_simplifiable_if (self , node ):
505
504
"""Check if the given if node can be simplified.
506
505
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.
512
510
"""
513
511
514
512
if self ._is_actual_elif (node ):
@@ -1301,8 +1299,8 @@ def _apply_boolean_simplification_rules(operator, values):
1301
1299
def _simplify_boolean_operation (self , bool_op ):
1302
1300
"""Attempts to simplify a boolean operation.
1303
1301
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.
1306
1304
"""
1307
1305
children = list (bool_op .get_children ())
1308
1306
intermediate = [
@@ -1323,8 +1321,8 @@ def _simplify_boolean_operation(self, bool_op):
1323
1321
def _check_simplifiable_condition (self , node ):
1324
1322
"""Check if a boolean condition can be simplified.
1325
1323
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.
1328
1326
"""
1329
1327
if not utils .is_test_condition (node ):
1330
1328
return
@@ -1503,7 +1501,7 @@ def _check_consider_using_with(self, node: nodes.Call):
1503
1501
self .add_message ("consider-using-with" , node = node )
1504
1502
1505
1503
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 '{}' ."""
1507
1505
if node .as_string () in {"list()" , "dict()" }:
1508
1506
inferred = utils .safe_infer (node .func )
1509
1507
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:
1514
1512
1515
1513
def _check_consider_using_join (self , aug_assign ):
1516
1514
"""We start with the augmented assignment and work our way upwards.
1515
+
1517
1516
Names of variables for nodes if match successful:
1518
1517
result = '' # assign
1519
1518
for number in ['1', '2', '3'] # for_loop
@@ -1638,7 +1637,8 @@ def _check_unnecessary_comprehension(self, node: nodes.Comprehension) -> None:
1638
1637
def _is_and_or_ternary (node ):
1639
1638
"""Returns true if node is 'condition and true_value or false_value' form.
1640
1639
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
1642
1642
"""
1643
1643
return (
1644
1644
isinstance (node , nodes .BoolOp )
@@ -1671,7 +1671,6 @@ def _check_consistent_returns(self, node: nodes.FunctionDef) -> None:
1671
1671
1672
1672
Args:
1673
1673
node (nodes.FunctionDef): the function holding the return statements.
1674
-
1675
1674
"""
1676
1675
# explicit return statements are those with a not None value
1677
1676
explicit_returns = [
@@ -1756,7 +1755,6 @@ def _is_node_return_ended(self, node: nodes.NodeNG) -> bool:
1756
1755
1757
1756
Returns:
1758
1757
bool: True if the node ends with an explicit statement, False otherwise.
1759
-
1760
1758
"""
1761
1759
# Recursion base case
1762
1760
if isinstance (node , nodes .Return ):
@@ -1828,9 +1826,9 @@ def _is_function_def_never_returning(self, node: nodes.FunctionDef) -> bool:
1828
1826
return False
1829
1827
1830
1828
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.
1834
1832
1835
1833
NOTE: produces a message only if there is a single return statement
1836
1834
in the function body. Otherwise _check_consistent_returns() is called!
0 commit comments